Reputation: 1061
I have two dataframes, each consisting of 3 columns with Year, Month and Day. df1 contains several other values that correspond to each date, and df2 contains different values. I want to merge both of the dataframes into one where the year, month and day are all in common. However, my first dataset goes from 1979-2017, but doesn't include all days or months 7-9. The second dataframe goes from 1979-2017 and includes every single day.
df1:
Year Month Day IVT IWV Morevalues...
1979 1 10 275 21
1979 1 12 365 22
1979 1 16 565 29
df2:
Year Month Day NAO PNA
1979 1 9 1.2 0.76
1979 1 10 1.1 0.85
1979 1 11 1.15 0.82
1979 1 12 1.13 0.83
What I want:
Year Month Day IVT IWV NAO PNA
1979 1 10 275 21 1.1 0.85
1979 1 12 365 22 1.13 0.83
Upvotes: 0
Views: 66
Reputation: 7504
Try this:
res = pd.merge(df1, df2, how='inner', on=['Year', 'Month', 'Day'])
Upvotes: 1