Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 960
rhaskett Avatar asked Apr 14 '15 22:04

rhaskett


People also ask

Can pandas read scientific notation?

Scientific notations isn't helpful when you are trying to make quick comparisons across your dataset. However, Pandas will introduce scientific notations by default when the data type is a float.


1 Answers

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
like image 89
JohnE Avatar answered Sep 21 '22 18:09

JohnE