时间数据与格式不匹配(匹配)
我有以下错误:
time data '23-MAY-2019 12:49:08' does not match format '%d-%m-%yyyy %H:%M:%S' (match)
这是我的代码:
dfbaseline['Date'] = pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')
怎么了?
I got the following error:
time data '23-MAY-2019 12:49:08' does not match format '%d-%m-%yyyy %H:%M:%S' (match)
this is my code:
dfbaseline['Date'] = pd.to_datetime(dfbaseline['Date'], format='%d-%m-%yyyy %H:%M:%S')
What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的日期格式有两个问题。
%m
用于匹配零填充数字的月格式(01至12)。
%y
将不得不匹配一个世纪以零填充的十进制数字(00,01,…,99),因此您必须更改,
%b
匹配一个月份的缩写名称(1月/2月/Mar等)%y
与Century匹配年数为十进制数字(0001、0002,…,2013年,2014年,2014年, …,9998,9999)参见
strftime()
和strptime()
格式代码以获取更多信息。There are two problems with your date format.
%m
is used to match Month in a zero-padded decimal numberformat(01 to 12).
%y
will match year without century as a zero-padded decimal number(00, 01, …, 99)So you have to change,
%b
to match Month in a locale’s abbreviated name(Jan/Feb/Mar etc)%Y
to match Year with century as a decimal number(0001, 0002, …, 2013, 2014, …, 9998, 9999)See
strftime()
andstrptime()
Format Codes for more information.您可以在此处查看用于将日期时间格式化为字符串的不同字符 -
https://www.ibm.com/docs/en/app-connect/11.0.0?topic=function-formatting-parsing-datetimes-as-strings#:~:text=Characters%20for%20formatting% 20a%20dateTime%20as%20a%20字符串
You can check out here, Different characters for formatting a DateTime as a string -
https://www.ibm.com/docs/en/app-connect/11.0.0?topic=function-formatting-parsing-datetimes-as-strings#:~:text=Characters%20for%20formatting%20a%20dateTime%20as%20a%20string