python - pandas: float_format and decimal sign not working properly -
i trying write pandas dataframe df
csv-file using pandas' to_csv
method following line:
df.to_csv(f, index=false, header=false, decimal=',', sep=' ', float_format='%.3f')
which gives csv-file following:
295.998 292.500 293.000 293.000 295.998 292.500 293.000 293.000 295.998 292.500 293.000 293.000
so float_format
option works pretty well, numbers have 3 decimal digits. however, decimal
option (decimal = ','
) not seem work, since decimal sign dot , not comma.
what interested following:
295,998 292,500 293,000 293,000 295,998 292,500 293,000 293,000 295,998 292,500 293,000 293,000
how can convience pandas use 3 decimal digits , desired comma decimal sign?
this behaviour bug in pandas version 0.15.2 since works fine after updating version 0.16.2 using following command:
sudo pip3 install -u pandas
which checked by
import pandas pd pd.__version__
giving
'0.16.2'
by using commands provided in question resulting csv-file looks desired:
295,998 292,500 293,000 293,000 295,998 292,500 293,000 293,000 295,998 292,500 293,000 293,000
Comments
Post a Comment