[英]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.