简体   繁体   English

ValueError: 时间数据 '2013/05/24 07:00:00' 与格式 '%Y-%m-%d %H:%M:%S' 不匹配

[英]ValueError: time data '2013/05/24 07:00:00' does not match format '%Y-%m-%d %H:%M:%S'

import csv
import datetime as dt
import datetime

import matplotlib.pyplot as plt


x,y = [],[]
csv_reader = csv.reader(open('noneventEventdetect.csv'))
for line in csv_reader:
    x.append(line[1])
    T = dt.datetime.strptime(line[0],'%Y-%m-%d %H:%M:%S')
    #print(T)
    y.append(T)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(y,x) 
fig.autofmt_xdate()



plt.show()

Example CSV data (python3.4): CSV 数据示例 (python3.4):

24/5/2013 7:00:00 1 24/5/2013 7:00:00 1

24/5/2013 7:00:00 2 24/5/2013 7:00:00 2

24/5/2013 7:00:00 3 24/5/2013 7:00:00 3

24/5/2013 7:00:00 4 24/5/2013 7:00:00 4

24/5/2013 7:00:00 5 24/5/2013 7:00:00 5

24/5/2013 7:00:00 6 24/5/2013 7:00:00 6

This error:这个错误:

Traceback (most recent call last):回溯(最近一次调用最后一次):

File "C:\\Users\\Kitravee\\Desktop\\New folder (4)\\sdf.py", line 12, in文件“C:\\Users\\Kitravee\\Desktop\\New folder (4)\\sdf.py”,第 12 行,在

T = dt.datetime.strptime(line[0],'%d-%m-%Y %H:%M:%S')

File "C:\\Python34\\lib_strptime.py", line 500, in _strptime_datetime文件“C:\\Python34\\lib_strptime.py”,第 500 行,在 _strptime_datetime

 tt, fraction = _strptime(data_string, format)

File "C:\\Python34\\lib_strptime.py", line 337, in _strptime文件“C:\\Python34\\lib_strptime.py”,第 337 行,在 _strptime

 (data_string, format))

ValueError: time data '2013/05/24 07:00:00' does not match format '%d-%m-%Y ValueError: 时间数据 '2013/05/24 07:00:00' 与格式 '%d-%m-%Y' 不匹配

%H:%M:%S' %H:%M:%S'

Time in your title is in a different format than the one in the file you provided, and both of them do not match the format.您标题中的时间格式与您提供的文件中的时间格式不同,并且两者都不匹配。

For the time in the file you need '%d/%m/%Y %H:%M' , for the time in your title you need '%Y/%m/%d %H:%M:%S'对于文件中的时间,您需要'%d/%m/%Y %H:%M' ,对于标题中的时间,您需要'%Y/%m/%d %H:%M:%S'

暂无
暂无

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

相关问题 ValueError:时间数据'2012-07-19 08:24:00'与格式'%Y-%m-%d H:M:S'不匹配 - ValueError: time data '2012-07-19 08:24:00' does not match format '%Y-%m-%d H:M:S' ValueError:时间数据'0000-00-00 00:00:00'与格式'%Y-%m-%d%H:%M:%S'不匹配 - ValueError: time data '0000-00-00 00:00:00' does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据 '2021-11-05 10:13:46+11:00' 与格式 '%y-%m-%d %H:%M:%S%z' 不匹配 - ValueError: time data '2021-11-05 10:13:46+11:00' does not match format '%y-%m-%d %H:%M:%S%z' Python 时间数据 '2008-01-24T00:00:00:000' 与格式 '%Y-%m-%d %H:%M :%S:%f' 不匹配 - Python time data '2008-01-24T00:00:00:000' does not match format '%Y-%m-%d %H:%M :%S:%f' 时间数据“2021-03-31 23:30:00”与格式“%Y-%m-%d %H:%M:S”不匹配 - time data '2021-03-31 23:30:00' does not match format '%Y-%m-%d %H:%M:S' 运行 scrapy spider 时出现此错误——> ValueError: time data '2022-10-10T13:00:00-07:00' does not match format '%Y-%m-%dT%H:%M: %S%z' - I get a this error when running scrapy spider ——> ValueError: time data '2022-10-10T13:00:00-07:00' does not match format '%Y-%m-%dT%H:%M:%S%z' 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' 时间数据“2022-01-07T02:05:1”与格式“%Y-%m-%d%H:%M:%S”不匹配 - time data '2022-01-07T02:05:1' does not match fotmat '%Y-%m-%d%H:%M:%S' 我有一个错误提示 ValueError: time data '31 days, 0:00:00' does not match format '%Y-%m-%d' - I have an error that says ValueError: time data '31 days, 0:00:00' does not match format '%Y-%m-%d' Python/Odoo:ValueError:时间数据“%Y-%m-%d”与格式“2020-10-09 00:00:0)”不匹配 - Python/Odoo: ValueError: time data '%Y-%m-%d' does not match format '2020-10-09 00:00:0)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM