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
How to Locate the Index With in a Nested List Python
How to Convert Column With String Type to Int Form in Pyspark Data Frame
Reading Contents of a Gzip File from a Aws S3 in Python
Python: Pickle.Load() Raising Eoferror
Python List - Only Keep Only-Positive or Only-Negative Values
Calculate Sklearn.Roc_Auc_Score for Multi-Class
Python Tkinter How to Update a Text Widget in a for Loop
Why Is Python No Longer Waiting for Os.System to Finish
Python Json Serialize a Decimal Object
Remove Last Few Characters in Pyspark Dataframe Column
Overlay a Smaller Image on a Larger Image Python Opencv
How to Print Superscript in Python
Python Anaconda - How to Safely Uninstall
How to Find the Average of Particular Numbers in a CSV File
How to Format an Integer to a Two Digit Hex
How to Read a Column Without Header from CSV and Save the Output in a Txt File Using Python