I have a dataframe with a date column converted using pd.to_datetime(). When I inspected the data I found few of these dates with year mentioned as 2216, which should have been 2016. Can you please help me change the year for these dates from 2216 to 2016
Date
0 2216-12-21
1 2216-12-23
2 2216-01-31
3 2016-12-23
4 2216-12-27
5 2216-12-25
6 2016-12-23
I tried using str.replace
df['Date'] = df['Date'].str.replace("2216","2016")
but got the following error
Can only use .str accessor with string values, which use np.object_ dtype in pandas
Thanks In advance
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…