pandas options and settings

pd.set_option(’precision’, 5)`
In [46]: pd.set_option(’max_colwidth’, 6)
In [47]: df
Out[47]:
  0     1   2     3
0 foo   bar bim   un...
1 horse cow ba... apple
In [55]: df=pd.DataFrame(np.random.choice([0,1,np.nan],size=(10,10)))
In [56]: df
Out[56]:
  0 1 2 3 4 5 6 7 8 9
0 0 1 1 0 1 1 0 NaN 1 NaN
1 1 NaN 0 0 1 1 NaN 1 0 1
2 NaN NaN NaN 1 1 0 NaN 0 1 NaN
3 0 1 1 NaN 0 NaN 1 NaN NaN 0
4 0 1 0 0 1 0 0 NaN 0 0
5 0 NaN 1 NaN NaN NaN NaN 0 1 NaN
6 0 1 0 0 NaN 1 NaN NaN 0 NaN
7 0 NaN 1 1 NaN 1 1 1 1 NaN
8 0 0 NaN 0 NaN 1 0 0 NaN NaN
9 NaN NaN 0 NaN NaN NaN 0 1 1 NaN
display.chop_threshold sets at what level pandas rounds to zero when it displays a Series of DataFrame.
Note, this does not effect the precision at which the number is stored.
In [67]: df=pd.DataFrame(np.random.randn(6,6))
In [68]: pd.set_option(’chop_threshold’, 0)
In [69]: df
Out[69]:
  0      1     2      3      4     5
0 -0.198 0.966 -1.523 -0.117 0.296 -1.048
1 1.641 1.906 2.772 0.089 -1.144 -0.633
2 0.925 -0.006 -0.820 -0.601 -1.039 0.825
3 -0.824 -0.338 -0.928 -0.840 0.249 -0.109
4 0.432 -0.461 0.337 -3.208 -1.536 0.410
5 -0.673 -0.741 -0.111 -2.673 0.864 0.061
In [70]: pd.set_option(’chop_threshold’, .5)
In [71]: df
Out[71]:
  0     1     2      3     4     5
0 0.000 0.966 -1.523 0.000 0.000 -1.048
1 1.641 1.906 2.772 0.000 -1.144 -0.633
2 0.925 0.000 -0.820 -0.601 -1.039 0.825
3 -0.824 0.000 -0.928 -0.840 0.000 0.000
4 0.000 0.000 0.000 -3.208 -1.536 0.000
5 -0.673 -0.741 0.000 -2.673 0.864 0.000
In [74]: pd.set_option(’colheader_justify’, ’right’)
In [75]: df
Out[75]:
      A    B C
0 0.933  0.3 0
1 0.289  0.2 0
2 1.325  0.2 0
3 0.589  0.7 0
4 0.531  0.1 0
5 -1.199 0.7 0
In [76]: pd.set_option(’colheader_justify’, ’left’)
In [77]: df
Out[77]:
  A      B   C
0 0.933  0.3 0
1 0.289  0.2 0
2 1.325  0.2 0
3 0.589  0.7 0
4 0.531  0.1 0
5 -1.199 0.7 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值