1

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

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Sep 30, 2021 at 20:18

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

Hi Gal, Thanks for wanting to help me out. However, when I use your solution I get the following error code: KeyError: "None of [Index(['Unname:0'], dtype='object')] are in the [columns]"
this is proboly as I made some mistake in the command column name I think it need to be Unnamed: 0 use you have the code use the correct name
Hi gal, sadly it still didnt work I still get all NaN in my lower table...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.