Avoiding Excel's Scientific Notation Rounding when Parsing with Pandas
Asked Answered
F

1

8

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?

Forbid answered 14/4, 2015 at 22:12 Comment(3)
A (very) brief glance at the API suggests no, but, what's wrong with converting that scientific notation into a plain number with your own code?Thermostatics
Pandas might very well be pulling the "full value". Just because it's displaying 1.35063e+11 doesn't mean there isn't more precision stored. Print out with a format like 15.0f to check.Sneer
Ahh... @Sneer you are correct. Its actually when I round trip and store the information down that I truly lose the precision though it appeared that I lost it earlier. This was easy to fix. If you want to write up a quick answer below I'll give you credit.Forbid
S
8

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
Sneer answered 15/4, 2015 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.