How to specify date format when using pandas.to_csv?
Since version v0.13.0 (January 3, 2014) of Pandas you can use the date_format
parameter of the to_csv method:
df.to_csv(filename, date_format='%Y%m%d')
You could use strftime
to save these as separate columns:
df['date'] = df['datetime'].apply(lambda x: x.strftime('%d%m%Y'))
df['time'] = df['datetime'].apply(lambda x: x.strftime('%H%M%S'))
and then be specific about which columns to export to csv:
df[['date', 'time', ... ]].to_csv('df.csv')