0

I have a dataframe with datetime index from 2006-01-19 to 2007-01-25 like this:

 YEAR DOY temperature datetime 2016-01-19 2016.0 NaN 2016-01-20 2016.0 NaN 2016-01-21 2016.0 NaN 2016-01-22 2016.0 NaN 2016-01-23 2016.0 NaN ..... 2017-01-24 2017.0 NaN 

All temperature values in the dataframe above are NaNs.

I want to join another dataframe containing temperature values for each day of the year (366 in all):

 YEAR DOY temperature 0 2013 1 3.66 1 2013 2 4.00 2 2013 3 1.38 3 2013 4 -0.44 ..... 4 2013 366 0.22 

I want to join these dataframes based on the DOY column so that e.g. day 22 of the first dataframe has temperature value that is obtained for day 22 from the second dataframe. I tried this:

df_a.merge(df_b, on='DOY', suffixes=('_x', '')) 

However, this does not work. How do I fix it?

1
  • I don't actually see a day of year column in the first df. Maybe that's your problem? Commented Mar 30, 2017 at 5:34

1 Answer 1

1

I usually use the full syntax:

merged = pd.merge(df_a, df_b, how='left', left_on='DOY', right_on='DOY', suffixes=('_x', '')) 

This way of merging is clearer to me personally.

You can look at the documentation on merging to find out more about merging.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.