float64 with pandas to_csv

As mentioned in the comments, it is a general floating point problem.

However you can use the float_format key word of to_csv to hide it:

df.to_csv('pandasfile.csv', float_format="%.3f")

or, if you don’t want 0.0001 to be rounded to zero:

df.to_csv('pandasfile.csv', float_format="%g")

will give you:

Bob,0.085
Alice,0.005

in your output file.

For an explanation of %g, see Format Specification Mini-Language.

Leave a Comment