I have a DataFrame with date as a column formatted as ddmmyy (e.g., 08JUN14). I can’t figure out how to format it for use as the x-axis of a matplotlib plot. From experimenting I understand that I need a string since:
datetime.strptime(“01Jul76”, ,"%d%b%y")
datetime.datetime(1976, 7, 1, 0, 0)
What I’m not understanding is how to format/use the entire DataFrame column? I tried converting the entire column to a string but that obviously isn’t correct (which I think makes sense after seeing the error message).
s = str(df.date)
d = datetime.strptime(s,"%d%b%y")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda\lib\_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data "('01Jul76', '01Sep76', … '15Jan15', '19Mar15')" does not match format '%d%b%y'.
I have searched and seen references to this issue but I don’t seem to be getting anywhere. Any guidance is greatly appreciated.
df['date'] = pd.to_datetime(df['date'])'01Jul76', '01Sep76', … '15Jan15', '19Mar15'and so this will not match'%d%b%y'which is expecting a single string to convert