I have a dataframe that includes a column of day numbers for which the year is known:
print (df)
year day time
0 2012 227 800
15 2012 227 815
30 2012 227 830
... ... ... ...
194250 2013 226 1645
194265 2013 226 1700
I have attempted to convert the day numbers to datetime %m-%d using:
import pandas as pd
df['day'] = pd.to_datetime(df['day'], format='%j').dt.strftime('%m-%d')
which gives:
year day time
0 2012 08-15 800
15 2012 08-15 815
30 2012 08-15 830
... ... ... ...
194250 2013 08-14 1645
194265 2013 08-14 1700
but this conversion is incorrect because the 227th day of 2012 is August 14th (08-14). I believe this error is down to the lack of year specification in the conversion.
How can I specify the year in the conversion to get a) %Y-%m-%d ; b) %m-%d ; c)%Y-%m-%dT%H:%M from the dataframe I have?
Thank you