简体   繁体   English

熊猫:抑制科学记数法?

[英]pandas: suppress scientific notation?

The suggested answers aren't working for me. 建议的答案对我不起作用。 What am I doing wrong?我究竟做错了什么?

在此处输入图片说明

Display options pertain to display of pandas objects.显示选项与熊猫对象的显示有关。 values returns a numpy array which is formatted independently from pandas. values返回一个 numpy 数组,该数组的格式独立于 Pandas。 You can use np.set_printoptions here:你可以在这里使用np.set_printoptions

s = pd.Series([1.2345678])

print(s)
#0    1.234568
pd.options.display.float_format = '{:.2f}'.format
print(s)
#0   1.23

print(s.values)
#[1.2345678]
pd.np.set_printoptions(2)
print(s.values)
#[1.23]

To suppress scientific notation you can specify a formatter:要禁止科学记数法,您可以指定格式化程序:

s = pd.Series([1.2345678e+14])

pd.np.set_printoptions(formatter={'float': lambda x: '{:.3f}'.format(x)})
print(s.values)
#[123456780000000.000]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM