0

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

enter image description here

rafaelc
  • 52,436
  • 15
  • 51
  • 78
Richard
  • 57,831
  • 112
  • 317
  • 501

1 Answers1

2

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]
Stef
  • 21,187
  • 1
  • 18
  • 46