Pandas DataFrame formatting

天涯浪子 提交于 2019-12-05 15:57:14

You can pass a function to float_format, so can be anything

In [1]:

df = DataFrame(dict(A = [1.2345,10000.12345,1]))
df
Out[1]:
A
0    1.23450
1    10000.12345
2    1.00000
3 rows × 1 columns
In [4]:

pd.set_option('display.float_format',
      lambda x: '{:,.4f}'.format(x) if abs(x) < 10000 else '{:,.0f}'.format(x))
In [5]:

df
Out[5]:
A
0   1.2345
1   10,000
2   1.0000
3 rows × 1 columns
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!