数字格式

pandas also allows you to set how numbers are displayed in the console. This option is not set through the set_options API.

Use the set_eng_float_format function to alter the floating-point formatting of pandas objects to produce a particular format.

For instance:

  1. In [79]: import numpy as np
  2. In [80]: pd.set_eng_float_format(accuracy=3, use_eng_prefix=True)
  3. In [81]: s = pd.Series(np.random.randn(5), index=['a', 'b', 'c', 'd', 'e'])
  4. In [82]: s/1.e3
  5. Out[82]:
  6. a -236.866u
  7. b 846.974u
  8. c -685.597u
  9. d 609.099u
  10. e -303.961u
  11. dtype: float64
  12. In [83]: s/1.e6
  13. Out[83]:
  14. a -236.866n
  15. b 846.974n
  16. c -685.597n
  17. d 609.099n
  18. e -303.961n
  19. dtype: float64

To round floats on a case-by-case basis, you can also use round() and round().