Bernhard van den Ende
Bernhard van den Ende

Reputation: 11

Copy data from one row in Dataframe A to a specific row in Dataframe B in python/pandas

I've been struggling with this assignment quite long now and I cant seem to get the correct solution. My problem is as follows: I have imported two worksheets (A & B) from an Excelfile and assigned these to two Dataframe variables. Worksheets A & B have rows with similar names however the cells in Worksheet B are empty whereas the cells in Worksheet A contain numbers. My assignment is to copy the rows from worksheet A to worksheet B. This needs to be done in a specific order. For example: in worksheet A the row sales revenue is at index 1, but in worksheet B the row sales revenue is at index 5. Does anybody know how to do this? Im an absolute beginner with python/pandas. I have included a printscreen of the situation

Upvotes: 1

Views: 130

Answers (1)

gal peled
gal peled

Reputation: 482

you need to merge the two tables using left join

#remove all Nan columns 
df_data3 = df_data3[['Unnamed:0']]
df_data3 = pd.merge(df_data3,df_data2,on='Unnamed:0',how='left')

see https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html for more option play with it a bit to better understand how this work

it is similar to SQL join

Upvotes: 1

Related Questions