本文介绍了ValueError:时间数据“ ['140209/1729']”与格式'%y%m%d /%H%M'不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这应该是一个非常简单的解决方案。
This should be a very simple solution.
我正在从列数组中读取日期,并且由于格式不匹配而出现错误:
I'm reading dates from a columnar array and getting an error due to a mismatch in format:
ValueError: time data "['140209/1729']" does not match format '%y%m%d/%H%M'
我尝试在循环遍历值时抛出[],但它不喜欢这种格式。
I've tried throwing in [] while looping through the values, but it does not like the format.
xdates = [datetime.datetime.strptime(str(formdate),'%y%m%d/%H%M') for formdate in DATE]
是否有更好的方法来定义日期np.genfromtxt?
Would there be a better way to define these at dates when doing a np.genfromtxt?
推荐答案
正如Ashwini Chaudhary所说,请使用 formdata [0]
而不是 str(formdata)
:
As Ashwini Chaudhary commented, use formdata[0]
instead of str(formdata)
:
>>> import datetime
>>> formdate = ['140209/1729']
>>> datetime.datetime.strptime(str(formdate), '%y%m%d/%H%M')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data "['140209/1729']" does not match format '%y%m%d/%H%M'
>>> datetime.datetime.strptime(formdate[0], '%y%m%d/%H%M')
datetime.datetime(2014, 2, 9, 17, 29)
这篇关于ValueError:时间数据“ ['140209/1729']”与格式'%y%m%d /%H%M'不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!