Skip to content

to_csv has changed the number #27771

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
honghong2333 opened this issue Aug 6, 2019 · 2 comments
Closed

to_csv has changed the number #27771

honghong2333 opened this issue Aug 6, 2019 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv

Comments

@honghong2333
Copy link

honghong2333 commented Aug 6, 2019

Code Sample, a copy-pastable example if possible

df1 = pd.read_csv("./data/test.csv")
print(df1)
df1.to_csv("./data/test1.csv")

test.csv has only one column "a" and one number is "656.964"when I prepare to use "to_csv" then it has changed to 656.9639999. 
I hope you can help solve this problem.
@tseth92
Copy link

tseth92 commented Aug 7, 2019

this is floating point precision problem . See this issue already raised and closed.:
#2069
So, most you can do is pass an argument in to_csv with float_format='%.3f' which will restrict your output to 3 decimal places

@alimcmaster1
Copy link
Member

@tseth92 answer should solve your problem. Feel free to reopen @Shanhong

@simonjayhawkins simonjayhawkins added Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv labels Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request IO CSV read_csv, to_csv
Projects
None yet
Development

No branches or pull requests

4 participants