df1 = pd.DataFrame(
columns=["A", "B", "C"],
data=[['2017-01-01',np.nan, "ok"], ['2017-02-01',8,"fine"], ['2017-03-01',100,np.nan]])
df1.to_excel('test.xlsx', index=False)
I have a dataframe that column is string. I want to export the df to excel and make column A the date type with the format DDMMMYYYY (i.e. instead of '2017-01-01' I need '01JAN2017').
I have tried two things that they don't work:
df1['A'] = pd.to_datetime(df1['A']).dt.strftime('%d%b%Y')
or
df1['A'] = pd.to_datetime(df1['A'], format="%d%b%Y")
How to do this?