I have a dataframe in the following format. The year is wrong in the Date column I want to be able to replace
Date Year
0 2013-04-13 2019
1 2013-04-13 2019
What's the best way of mapping the Year into the datetime column?
Using replace
df.apply(lambda x :x.Date.replace(year=x.Year),1)
Out[307]:
0 2019-04-13
1 2019-04-13
dtype: datetime64[ns]
Try:
df.Date += pd.to_timedelta(df.Year - df.Date.dt.year, unit='Y')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With