Reputation: 405
I am in some sort of Python Pandas datetime purgatory and cannot seem to figure out why the below throws an error. I have a simple date, a clear format string, and a thus far unexplained ValueError. I've done quite a bit of searching, and can't seem to get to the bottom of this.
On top of the issue below, what is the concept surrounding the format string referred to as? In other words, where can I learn more about how the %m, %d, and %Y can be changed and reconfigured to specify different formats?
Thanking you in advance from purgatory.
In [19]: import pandas as pd
In [20]: date = '05-01-11'
In [21]: print type(date)
<type 'str'>
In [22]: pd.to_datetime(date, format = '%m-%d-%Y')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-22-24aff1dbfb25> in <module>()
----> 1 pd.to_datetime(date, format = '%m-%d-%Y')
/Users/amormachine/anaconda/lib/python2.7/site-packages/pandas/tseries/tools.pyc in to_datetime(arg, errors, dayfirst, utc, box, format, coerce, unit, infer_datetime_format)
323 return _convert_listlike(arg, box, format)
324
--> 325 return _convert_listlike(np.array([ arg ]), box, format)[0]
326
327 class DateParseError(ValueError):
/Users/amormachine/anaconda/lib/python2.7/site-packages/pandas/tseries/tools.pyc in _convert_listlike(arg, box, format)
311 return DatetimeIndex._simple_new(values, None, tz=tz)
312 except (ValueError, TypeError):
--> 313 raise e
314
315 if arg is None:
ValueError: time data '05-01-11' does not match format '%m-%d-%Y' --> THE HELL IT DOESN'T!
Upvotes: 1
Views: 1714