2

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]

Would there be a better way to define these at dates when doing a np.genfromtxt?

wuffwuff
  • 730
  • 2
  • 9
  • 19

1 Answers1

2

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)
falsetru
  • 357,413
  • 63
  • 732
  • 636