Pandas To_Csv: Suppress Scientific Notation in CSV File When Writing Pandas to Csv

pandas to_csv: suppress scientific notion for data frame with mixed types

The float_format argument should be a str, use this instead

df.to_csv('example.csv', float_format='%f')

Converting .csv file into scientific notation with pandas

What options do I have?

Harness float_format of .to_csv. Consider following example

import pandas as pd
df = pd.DataFrame({'x':[0.1,0.01,0.001]})
df.to_csv("file.csv",float_format="%e",header=False,index=False)

produces file.csv

1.000000e-01
1.000000e-02
1.000000e-03

Pandas - Decimal format when writing to_csv instead of scientific

Check the documentation for to_csv(), you'll find an attribute called float_format

df.to_csv(..., float_format='%.6f')

you can define the format you want as defined in the Format Specification Mini-Language



Related Topics



Leave a reply



Submit