Code

import pandas as pd

df = pd.DataFrame(["3100000035155588379531799826432", "3100000035155588433002733375488", "3100000035155588355694446120960"])
df.to_csv("data.csv")

The following display is opened using Excel, Show in Excel is wrong.

Result

  0
0 3.10E+30
1 3.1E+30
2 3.1E+30

Expect

  0
0 3100000035155588379531799826432
1 3100000035155588433002733375488
2 3100000035155588355694446120960

How to save long numbers to CSV file, use the string type save?

Comment From: TomAugspurger

Could you post the output of pd.show_versions as requested? My output of your code looks correct.

Comment From: jreback

In [7]: pd.DataFrame(["3100000035155588379531799826432", "3100000035155588433002733375488", "3100000035155588355694446120960"]).to_csv()
   ...: 
   ...: 
Out[7]: ',0\n0,3100000035155588379531799826432\n1,3100000035155588433002733375488\n2,3100000035155588355694446120960\n'

Comment From: CarGod

@jreback @TomAugspurger I think it may be because of the Excel display problems.

I tried to change the code, This is the correct way to use Excel.

import pandas as pd

df = pd.DataFrame(["3100000035155588379531799826432", "3100000035155588433002733375488", "3100000035155588355694446120960"])
df = "\t" + df
df.to_csv("data.csv")

Comment From: akshayutekar99

`import pandas as pd

df = pd.DataFrame(["3100000035155588379531799826432","3100000035155588355694446120960"],dtype="string") df.to_csv("data.csv")`

Maybe this can help