pandas

Searching for values in large dataframe with unnamed columns

Searching for values in large dataframe with unnamed columns Question: I have a dataframe with ~300 columns in the following format: | Column1 | Column2 | Column3 | Column5 | ————| ————– |———–|———- | Color=Blue | Location=USA | Name=Steve| N/A | Location=USA| ID=123 | Name=Randy| Color=Purple | ID=987 | Name=Gary | Color=Red | Location=Italy What …

Total answers: 3

plot multiple lists

plot multiple lists Question: I am Building a GUI by Python and want to plot the the daily bonus of employees depends on the user plotting target: Bob=[100,30,50,90] Sammy=[10,60,90,200] Tom=[70,90,90,90] # input from GUI User is Tom ploting_target=’Tom’ if ploting_target==’Tom’:` plt.plot([0,1,2,3], Tom) elif ploting_target==’Sammy’: plt.plot([0,1,2,3], Sammy) plt.plot([0,1,2,3], Tom) ____________________________________________ #expecting #find_target=list_of_employee.index(ploting_target) #plt(plot([0,1,2,3], list_of_employee[find_target]) Asked By: …

Total answers: 1

Python pandas rolling sum positive number with duplicate timestamps

Python pandas rolling sum positive number with duplicate timestamps Question: have a dataframe with two columns like below. One column is datetime and another is purely numbers. I’d like to sum all positive numbers of last 5 minutes.Tried df[‘positive’] = df[‘number’].rolling(‘5T’).sum() but didn’t work. Somehow, getting a ValueError: window must be an integer 0 or …

Total answers: 2

Duplicate pairs of rows side by side in pandas given certain condition

Duplicate pairs of rows side by side in pandas given certain condition Question: I have the following code: import pandas as pd data = { ‘Col1’: [‘John 1’, ‘John 2’, ‘John 3’, ‘Kyle 1’, ‘Kyle 3’, ‘Kyle 2’], ‘Col2’: [‘B’, ‘C’, ‘E’, ‘F’, ‘F’, ‘S’], ‘Col3’: [‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘2’] } df = …

Total answers: 4

Copy values to next rows based on multiple conditions without a for loop

Copy values to next rows based on multiple conditions without a for loop Question: I have a dataframe with 3 columns. For the most part, column C is empty. There is only a value for each instance when the value in column A is not equal to the value in column A on the previous …

Total answers: 1

Dividing two columns of pandas daraframe and keep the header name

Dividing two columns of pandas daraframe and keep the header name Question: With the following data frame ID,WEIGHT,I1,I2,I4 1,0.2,839,1664,3266 2,0.1,851,863,858 3,0.4,1018,1999,3982 4,0.3,878,1724,3447 I want to iterate over I1..I4 and create new data frames by joining the WEIGHT column and I_i/I1. The following code works fine for i in range(3,5): df_new = pd.concat([df[‘WEIGHT’], df.iloc[:,i]/df.iloc[:,2]], axis=1) print(df_new) …

Total answers: 6

Creating complex html tables with pandas

Creating complex html tables with pandas Question: I am struggling with creating a pandas based html table that will look like the one in the attached picture. As you can see there are multiple table headers, colspans, rowspans, shadings, etc. In more detail, I am developing a reporting system, and I want to be able …

Total answers: 2

Rearrange the columns of a pandas DataFrame based on row number

Rearrange the columns of a pandas DataFrame based on row number Question: There is a dataframe: import pandas as pd df = pd.DataFrame(data = {‘a’:[3,0,2,1],’b’:[4,3,2,1],’c’:[3,2,1,0],’d’:[4,3,2,0]}) print(df) >>> df a b c d 0 3 4 3 4 1 0 3 2 3 2 2 2 1 2 3 1 1 0 0 How to rearrange(sort?) …

Total answers: 3

Iterate through chunks of a pandas Dataframe

Iterate through chunks of a pandas Dataframe Question: I have a pandas.DataFrame that looks like the following: Week Monday Tuesday Wednesday Thursday Friday City A 100 300 x z w City B 200 400 y q p None None None None None None Week Monday Tuesday Wednesday Thursday Friday City A 150 320 a c …

Total answers: 2