Pandas 参数设置

1 设置DataFrame最大显示行数

# if the max displaying rows is 5
pd.set_option('display.max_rows', 5)

2 设置DataFrame最大显示列数

# if the max displaying columns is 30
pd.set_option('display.max_colums', 30)

3 设置每列最大显示宽度

# if the max displaying colwidth is 100
pd.set_option('display.max_colwidth', 100)

4 指定某个数的元素显示为0

# 通过display.chop_threshold参数, 我们在不修改原始参数的情况下,指定数据框中绝对值小于阈值的数显示为0
pd.set_option('display.chop_threshold', 0.5)

5 格式化浮点数

# 
pd.set_option('display.float_format', '${:,.2f}'.format)

6 控制小数打印的精度

# 除了 5格式化浮点数中的方法,我们还可以通过 display.precision 参数来设置精度
pd.set_option('display.precision', 4)

7 临时修改参数

# 有时我们希望仅对当前设置某些参数,并不修改全局参数我们使用 with 关键字

with pd.option_context('display.precision', 5):
  df.head()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值