熊猫pd.options.display.max_rows无法正常工作

时间:2019-09-09 20:26:07

标签: python pandas

我在Jupyter Lab中使用的是熊猫0.25.1,无论pd.options.display.max_rows设置为多少,我最多可以显示10行。

但是,如果pd.options.display.max_rows设置为小于10,则生效;如果pd.options.display.max_rows = None,则所有行都显示。

您知道如何让超过10的pd.options.display.max_rows生效吗?

2 个答案:

答案 0 :(得分:6)

pandas v0.25.1的最终答案

  • 要显示所有行,请将max_rows设置为大于DataFrame中的行数。
  • 要在数据帧被截断时显示多于10行,请将min_rows设置为大于10。

发现与注释:

pd.set_option('display.max_rows', x)pd.options.display.max_rows = x(其中x是某个数字)都应该起作用。

其他有用的pandas选项:

pd.set_option('display.max_columns', 200)
pd.set_option('display.max_rows', 100)
pd.set_option('display.min_rows', 100)
pd.set_option('display.expand_frame_repr', True)

get.options返回当前值:

pd.get_option("display.max_rows")

更新:

  • 经过一些发现测试,如果该设置大于DataFrame中的行数,则该设置仅显示更多行。
    • 如果pd.set_option('display.max_rows', 100),但DataFrame有200行,则只会显示10行。
    • 如果pd.set_option('display.max_rows', 200),但DataFrame有100行,则将显示所有100行。

根据熊猫文档:

  • display.max_rows:默认= 60
    • 这设置了在打印各种输出时熊猫应输出的最大行数。例如,此值确定是完整打印数据框的repr()还是仅打印截断的或摘要的repr。 “无”值意味着无限。
  • display.min_rows:默认= 10
    • 在截短的repr中显示的行数(超过max_rows时)。当max_rows设置为None或0时被忽略。当设置为None时,遵循max_rows的值。
  • display.large_repr:默认=截断
    • 对于超过max_rows / max_cols的DataFrame,repr(和HTML repr)可以显示截断的表(默认值),或者从df.info()切换到视图(早期版本的熊猫)。允许的设置[[truncate],“ info”]

答案 1 :(得分:-1)

min_rows 显示要从顶部(头部)和底部(尾部)开始显示的行数,它将被平均分割......尽管输入​​的是奇数。如果只想显示一定数量的行而不将其读入内存,

另一种方法是使用 nrows = 'putnumberhere'

e.g. results = pd.read_csv('ex6.csv', nrows = 5) # display 5 rows from the top 0 - 4

如果数据框有大约 100 行并且您只想显示从顶部开始的前 5 行...NO TAIL 使用 .nrows