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

rbi*_*nun 5 python pandas

我在Jupyter Lab中使用pandas 0.25.1,无论pd.options.display.max_rows设置什么,我最多可以显示10行。

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

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

Tre*_*ney 44

最终答案截至 pandas v0.25.1

  • 要显示所有行,请设置max_rows大于DataFrame.
  • 要在数据框被截断时显示超过 10 行,请将其设置为min_rows大于 10。
  • 200多行数据,如果max_rows是200和min_rows是20,会显示头部10,尾部10。
  • 200多行数据,如果max_rows是200和min_rowsis None,会显示头部100,尾部100。

发现与注意事项:

这两个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)
Run Code Online (Sandbox Code Playgroud)

get.options 返回当前值:

pd.get_option("display.max_rows")
Run Code Online (Sandbox Code Playgroud)

更新:

  • 经过一些发现测试后,如果设置大于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/ 的DataFrames max_cols,repr(和 HTML repr)可以显示一个截断的表格(默认),或者切换到视图df.info()(在早期版本的 Pandas 中的行为)。允许的设置,['truncate', 'info']