简体   繁体   English

ValueError: 时间数据“00:01:29:06”与格式“%d:%H:%M:%S”不匹配

[英]ValueError: time data '00:01:29:06' does not match format '%d:%H:%M:%S'

I need to convert dataframe in columns duration to datetime format to anlysis average or max/min but it now work need some help thanks.我需要将列持续时间中的数据帧转换为日期时间格式到分析平均值或最大值/最小值,但它现在需要一些帮助,谢谢。 dataframe数据框

df['duration'] =pd.to_datetime(df['duration'], format='%d:%H:%M:%S')

The reason of the error is that the %d format only accepts values between 01 and 31 (since it stands for "day of the month").错误的原因是%d格式只接受0131之间的值(因为它代表“一个月中的某一天”)。 00 is then not valid. 00则无效。

The best workaround I could figure (someone might suggest something better) is to use regular expression to convert the strings contained in the duration column into some valid string as in the following example:我能想到的最佳解决方法(有人可能会提出更好的建议)是使用正则表达式将duration列中包含的字符串转换为一些有效字符串,如下例所示:

df['duration']=pd.to_timedelta(df.duration.str.replace(r"(?P<day>\d+):", r'\g<day> days ', 1))

I've no idea about the time complexity of the above example (in case of have a big table to convert).我不知道上面例子的时间复杂度(如果有一个大表要转换)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:时间数据 '19/06/18 10:40:01' 与格式 '%d/%m/%Y %H:%M:%S' 不匹配 - ValueError: time data '19/06/18 10:40:01' does not match format '%d/%m/%Y %H:%M:%S' ValueError:时间数据&#39;1/1/2016 00:09:55&#39;与格式&#39;%m /%d /%y%H:%M:%S&#39;不匹配 - ValueError: time data '1/1/2016 00:09:55' does not match format '%m/%d/%y %H:%M:%S' ValueError:时间数据“在00天23:07:56”与格式“在%d天%H:%M:%S”不匹配 - ValueError: time data 'In 00 days 23:07:56' does not match format 'In %d days %H:%M:%S' ValueError: 时间数据 &#39;2013/05/24 07:00:00&#39; 与格式 &#39;%Y-%m-%d %H:%M:%S&#39; 不匹配 - ValueError: time data '2013/05/24 07:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError:时间数据&#39;0000-00-00 00:00:00&#39;与格式&#39;%Y-%m-%d%H:%M:%S&#39;不匹配 - ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' twint 发布时间数据“2020–04–29 00:00:00”与格式“%Y-%m-%d %H:%M:%S”不匹配 - twint issue time data '2020–04–29 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据 &#39;2020-01-31T15:16:21+00:00&#39; 与格式 &#39;%Y-%m-%dT%H:%M:%S%z&#39; 不匹配 - ValueError: time data '2020-01-31T15:16:21+00:00' does not match format '%Y-%m-%dT%H:%M:%S%z' Python 时间数据 &#39;2008-01-24T00:00:00:000&#39; 与格式 &#39;%Y-%m-%d %H:%M :%S:%f&#39; 不匹配 - Python time data '2008-01-24T00:00:00:000' does not match format '%Y-%m-%d %H:%M :%S:%f' ValueError:时间数据“6.9141387939453125e-06”与格式“%H/%M/%S”不匹配 - ValueError: time data '6.9141387939453125e-06' does not match format '%H/%M/%S' ValueError:时间数据“ 1:00:00”与格式“%H:%M:%S”不匹配 - ValueError: time data ' 1:00:00' does not match format '%H:%M:%S'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM