Reputation: 707
I have two dataframe:
df1 df2
№ year № year
1 2010 373
2 2010 374
3 2010 375
4 2010 376
5 2010 ...
...
372 2017
373 2017
374 2017
375 2017
376 2017
377 2017
...
899 2026
900 2026
901 2026
I need to find all the values from column "№" of the df2 in the df1 and fill the column "year" in the df2 with values from the df1. The result should look like this:
df2
№ year
373 2017
374 2017
375 2017
376 2017
...
I tried to do it this way
df2['year'] = np.where(df2['№'] == df1['№'] , 'Insert value from df1['year'], '0')
I first tried to insert '1', instead of a year, to check if the code is working, it got me such an error
ValueError: Can only compare identically-labeled Series objects
Any suggestion, please?
Upvotes: 2
Views: 416