For an automation, I need to convert an excel file to csv along with some modifications in some columns. In one of the column I need to change the time stamp to %Y-%m-%d %H:%M:%S'. Currently I am able to do everything and the change reflects on the dataframe except that when I convert it to csv, the timestamp format changes,
This is the code I have been trying now
df=pd.read_excel(file,headers=0,index=False)
print(df.head())
df['Reported On '] = pd.to_datetime(df['Reported On '])
df['Reported On ']= df['Reported On '].apply(lambda x: dt.datetime.strftime(x, '%Y-%m-%d %H:%M:%S'))
df.to_csv(csv_name,index=False)
The Reported On column in CSV gives the value :8/10/2017 10:50
While if I convert the dataframe to excel, it gives me the required format.
Is it the problem of csv ?
applyconvert that column intostrthen tryto_csvit may work for you....object... BTW tested with pandas 0.23.4 on Python 3.7