The default output format of
12/14/2012 12:00:00 AM
I cannot figure out how to output only the date part with specific format:
or date and time in two separate columns in the csv file:
The documentation is too brief to give me any clue as to how to do these. Can anyone help?
Here is Solutions:
We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.
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')
To export as a timestamp, do this:
%s format is not documented in python/pandas but works in this case.
Note that the timestamp miliseconds format
%Q does not work with pandas (you’ll have a litteral
%Q in the field instead of the date). I caried my sets with python 3.6 and pandas 0.24.1
Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂