the merging of two datasets on a column in a common

You should do two things: 1) Specify the minimum columns required ([['Info', 'User']]) and how='left', so you don’t merge another Year column in. You had the dataframes flipped around in your merge:

pd.merge(df2, df1[['Info', 'User']], on=['User'], how='left')

Out[1]: 
         Date   User  Year         Note  Info
0  2012-02-13  user1  2012          NaN  24.0
1  2012-01-11  user4  2011         Paid  24.5
2  2012-02-13  user1  2012  Need review  24.0
3  2012-02-14  user3  2010          NaN  12.0
4  2012-02-13  user2  2012          NaN   0.0
5  2012-02-11  user2  2012  Need review   0.0

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top