pandas 在熊猫中使用科学记数法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31983341/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using scientific notation in pandas
提问by ostroon
I found plenty of answers on how to suppress scientific notation in pandas, but how do I enableit? I found the option pd.set_option('precision', 2)but it does not turn large numbers into scientific notation.
我找到了很多关于如何在 Pandas 中抑制科学记数法的答案,但如何启用它?我找到了该选项,pd.set_option('precision', 2)但它不会将大数转换为科学记数法。
For example, I would like the number 123066.14to 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.
例如,我希望将数字123066.14格式化为1.23E+5. 我正在使用pandas.DataFrame, 在导出/打印时设置整列的格式会很有用。
回答by EdChum
OK, I figured this out, you can use set_optionand pass a format string to option 'display.float_format':
好的,我想通了,您可以使用set_option格式字符串并将其传递给 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

