rhaskett
rhaskett

Reputation: 1962

Avoiding Excel's Scientific Notation Rounding when Parsing with Pandas

I have an excel file produced automatically with occasional very large numbers like 135061808695. In the excel file when you click on the cell it shows the full number 135061808695 however visually with the automatic "General" format the number appears as 1.35063E+11.

When I use ExcelFile in Pandas the it pulls the value in scientific notation 1.350618e+11 instead of the full 135061808695. Is there any way to get Pandas to pull the full value without going in an messing with the excel file?

Upvotes: 8

Views: 8308

Answers (1)

JohnE
JohnE

Reputation: 30444

Pandas might very well be pulling the full value but not showing it in its default output:

df = pd.DataFrame({ 'x':[135061808695.] })

df.x
0    1.350618e+11  
Name: x, dtype: float64

Standard python format:

print "%15.0f" % df.x
135061808695

Or in pandas, convert to an integer type to get integer formatting:

df.x.astype(np.int64)

0    135061808695
Name: x, dtype: int64

Upvotes: 8

Related Questions