简体   繁体   中英

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. You can use np.set_printoptions here:

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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