I have pandas column like following
January 2014
February 2014
I want to convert it to following format 201401 201402 I am doing following
df.date = pd.to_datetime(df.date,format= '%Y%B')
But,it gives me an error.
You shouldn't need the format string, it just works:
In [207]:
pd.to_datetime('January 2014')
Out[207]:
Timestamp('2014-01-01 00:00:00')
besides your format string is incorrect, it should be '%B %Y':
In [209]:
pd.to_datetime('January 2014', format='%B %Y')
Out[209]:
Timestamp('2014-01-01 00:00:00')
df['date'] = pd.to_datetime(df['date'])should just work