Reputation: 11
I have a dateframe column in Python that is in the format YYMM
. E.g January 1996
is 9601
.
I'm having a hard time converting it from 9601 to a useable date time format. I want the new format to be 01-01-1996
. Does anyone have any suggestions? I tried pd.to_datetime
function but it's not getting the results I'm looking for.
Upvotes: 1
Views: 1295
Reputation: 863351
Use to_datetime
with parameter format
:
df = pd.DataFrame({'col':['9601', '9705']})
df['col'] = pd.to_datetime(df['col'], format='%y%m')
print (df)
col
0 1996-01-01
1 1997-05-01
Upvotes: 5