Using scientific notation in pandas

后端 未结 1 1966
囚心锁ツ
囚心锁ツ 2020-12-17 19:10

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)

相关标签:
1条回答
  • 2020-12-17 19:48

    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
    
    0 讨论(0)
提交回复
热议问题