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()

猜你喜欢

转载自blog.csdn.net/qq_32963855/article/details/110357310