18

I found plenty of answers on how to suppress scientific notation in pandas, but how do I enable it? I found the option pd.set_option('precision', 2) but it does not turn large numbers into scientific notation.

For example, I would like the number 123066.14 to be formatted as 1.23E+5. I am using a pandas.DataFrame, and it would be useful to set the formatting for an entire column when exporting/printing.

sougonde
  • 3,438
  • 3
  • 26
  • 35

1 Answers1

23

OK, I figured this out, you can use set_option and pass a format string to option 'display.float_format':

In [76]:
pd.set_option('display.float_format', '{:.2g}'.format)

In [78]:
pd.Series(data=[0.00000001])

Out[78]:
0   1e-08
dtype: float64

EDIT

to match your desired output:

In [79]:
pd.set_option('display.float_format', '{:.2E}'.format)
pd.Series(data=[0.00000001])

Out[79]:
0   1.00E-08
dtype: float64
EdChum
  • 376,765
  • 198
  • 813
  • 562
  • 2
    By the way, I found `:.2E` to be a better formatting. It uses a capital `E` while also ensuring 2 digits after the decimal point. The `g` mode will hide the second `0`. – sougonde Aug 13 '15 at 09:22
  • for whatever reason e/E keeps 1 more digit than g/G. The capitalization of e and g selects whether the output uses small `e` or big `E`. – fantabolous May 18 '23 at 03:00