Skip to content
Advertisement

Tag: pandas

groupby weighted average and sum in pandas dataframe

I have a dataframe: I need a sum of adjusted_lots , price which is weighted average , of price and adjusted_lots , grouped by all the other columns , ie. grouped by (contract, month , year and buys) Similar solution on R was achieved by following code, using dplyr, however unable to do the same in pandas. is the same

Format y axis as percent

I have an existing plot that was created with pandas like this: The y axis is format as float and I want to change the y axis to percentages. All of the solutions I found use ax.xyz syntax and I can only place code below the line above that creates the plot (I cannot add ax=ax to the line above.)

Replacing Header with Top Row

I currently have a dataframe that looks like this: I’m looking for a way to delete the header row and make the first row the new header row, so the new dataframe would look like this: I’ve tried stuff along the lines of if ‘Unnamed’ in df.columns: then make the dataframe without the header but I don’t seem to be

Import SAS data file into python data frame

I’m working on a data set (PSID) that gives data in a SAS format (a .txt and another file containing instructions to interpret the data). I cannot find anything in Python to read this type of data. Does anyone know of a pre-existing module/script to read SAS data? Edit (added from a comment to an answer): The data is in

Pandas read multiindexed csv with blanks

I’m struggling with properly loading a csv that has a multi lines header with blanks. The CSV looks like this: What I would like to get is: When I try to load with pd.read_csv(file, header=[0,1], sep=’,’), I end up with the following: Is there a way to get the desired result? Note: alternatively, I would accept this as a result:

Change Series inplace in DataFrame after applying function on it

I’m trying to use pandas in order to change one of my columns in-place, using simple function. After reading the whole Dataframe, I tried to apply function on one Series: And it’s working great. The only problem occurs when I try to put it back into my DataFrame: or: Throwing the following warning: Of Course, I can set the DataFrame

Advertisement