Skip to content Skip to sidebar Skip to footer

Pandas: Suppress Scientific Notation?

The suggested answers aren't working for me. What am I doing wrong?

Solution 1:

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}'.formatprint(s)
#0   1.23print(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]

Post a Comment for "Pandas: Suppress Scientific Notation?"