[英]Cant convert string to datetime Pandas to_datetime() out of time error
Error message: OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-05-22 00:00:00
错误消息: OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-05-22 00:00:00
Given dataframe给定数据框
Date日期 | Value价值 |
---|---|
May 22 5月22日 | 1K 1K |
Apr 22 4月22日 | 2K 2K |
... ... | ... ... |
Jan 00 1月00日 | 10K 10K |
I have tried convert it to string and called the to_datetime()
我尝试将其转换为字符串并调用to_datetime()
df['Date'] = df['Date'].apply(str)
df['Date'] = pd.to_datetime(df['Date'])
My goal is to convert Date to datetime 05-2022, 04-2022, ... 01-2000
我的目标是将日期转换为日期05-2022, 04-2022, ... 01-2000
You can manually specify format
argument of pd.to_datetime
您可以手动指定pd.to_datetime
的format
参数
df['Date'] = pd.to_datetime(df['Date'], format='%b %y')
print(df)
Date Value
0 2022-05-01 1K
1 2022-04-01 2K
2 2000-01-01 10K
print(df['Date'].dt.strftime('%m-%Y'))
Date Value
0 05-2022 1K
1 04-2022 2K
2 01-2000 10K
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.