I have an a dataframe:
date USD
2003-01-31T18:24:11 0300 40
I needed to make format like year-month like 2003-01
Tryed to do:
final_df['date'] = pd.to_datetime(final_df['date'], format='%Y-%m')
and take exception:
'Styler' object is not subscriptable
CodePudding user response:
I'm not sure that this is the error your got but you need to use pandas.Series.dt.strftime
.
Try this :
final_df["Date"] = pd.to_datetime(final_df['date']).dt.strftime("%Y-%m")
# Output:
print(final_df)
date USD Date
0 2003-01-31T18:24:11 0300 40 2003-01