I have a dataframe of some float datatype column and 2 date type column.Sample
I J P V
1.2 11 2011-12-03 2015-08-07 19:14:07
1.0 18 2011-12-03 2015-08-07 19:14:07
1.8 21 2011-12-03 2015-08-07 19:14:07
Now i want I and J col should be formatted yo .4f (after decimal 4 places).So 1.2 should reflect as 1.2000, In J col 18 should reflect as 18.0000. And date field should be formatted to YYYY-MM-DD for P and YYYY-MM-DD HH:MM:SS.
Yes it looks fine in dateframe..i formatted the I & J column by
df['I'] = ['%.4f'%x for x in df['I']]
df['J'] = ['%.4f'%x for x in df['J']]
## 1.2000, 11.0000 # fine
Then tried to give a csv output, But in that again 1.2000 reflected as 1.2 and 11.0000 as 11,,,, And date become 03/12/2011,07/08/2015 19:14:07 respectively for first row date value in dataframe.
Which is not fullfilling the requirement(4 decimal place and date as YYYY_MM_DD).
I tried doing
df['P'] = [x.strftime('%Y-%m-%d') for x in df['P']]
df['V'] = [x.strftime('%Y-%m-%d %H:%M:%S') for x in df['V']]
#Then from doc and google tried doing
df.to_csv('D:/New.csv',date_format='%Y-%m-%d %H:%M:%S',index=False) ### not worked
df.to_csv('D:/changed_2.csv',float_format='string',date_format='%Y-%m-%d %H:%M:%S',index=False) ###Also not Working
Please suggest how can i give a csv file with this requirement.