如何增加 pandas 系列中截断显示的行数

bea*_*rdc 1 python printing console series pandas

在终端中,我pd.options.display.max_rows设置为 60。但是对于超过 60 行的系列,显示内容会被截断为仅显示 10 行。如何增加显示的截断行数?

例如,以下内容(在max_rows设置范围内)显示 60 行数据:

s = pd.date_range('2019-01-01', '2019-06-01').to_series()
s[:60]
Run Code Online (Sandbox Code Playgroud)

但如果我要求 61 行,它会被严重截断:

In [44]: s[:61]
Out[44]:
2019-01-01   2019-01-01
2019-01-02   2019-01-02
2019-01-03   2019-01-03
2019-01-04   2019-01-04
2019-01-05   2019-01-05
                ...
2019-02-26   2019-02-26
2019-02-27   2019-02-27
2019-02-28   2019-02-28
2019-03-01   2019-03-01
2019-03-02   2019-03-02
Freq: D, Length: 61, dtype: datetime64[ns]
Run Code Online (Sandbox Code Playgroud)

我怎样才能设置它,以便每次超出限制时我都能看到 20 行max_rows

CDJ*_*DJB 7

文档中,您可以使用pd.options.display.min_rows.

一旦超过 display.max_rows,display.min_rows 选项将确定截断的 repr 中显示的行数。

例子:

>>> pd.set_option('max_rows', 59)
>>> pd.set_option('min_rows', 20)
>>> s = pd.date_range('2019-01-01', '2019-06-01').to_series()
>>> s[:60]
2019-01-01   2019-01-01
2019-01-02   2019-01-02
2019-01-03   2019-01-03
2019-01-04   2019-01-04
2019-01-05   2019-01-05
2019-01-06   2019-01-06
2019-01-07   2019-01-07
2019-01-08   2019-01-08
2019-01-09   2019-01-09
2019-01-10   2019-01-10
                ...
2019-02-20   2019-02-20
2019-02-21   2019-02-21
2019-02-22   2019-02-22
2019-02-23   2019-02-23
2019-02-24   2019-02-24
2019-02-25   2019-02-25
2019-02-26   2019-02-26
2019-02-27   2019-02-27
2019-02-28   2019-02-28
2019-03-01   2019-03-01
Freq: D, Length: 60, dtype: datetime64[ns]
Run Code Online (Sandbox Code Playgroud)