Pandas没有显示我通过max_rows设置的所有行

前端开发 2026-07-10

Pandas没有按我用display.max_rows指定的所有行显示

I have specified 100 rows for pandas to show using:

pd.set_option('display.max_rows', 100)

But when I display the DataFrame, it only shows 10 rows.

我试过使用 display.height,但它已被弃用(在过去这曾解决过这个问题)。

When I set the option to show all rows, they are displayed correctly.

它只显示这10行:

   0
   1
   2
   3
   4
 ...
1455
1456
1457
1458
1459

注: DataFrame的形状是 (1460, 80)。

Why is display.max_rows being ignored? How can I fix this to show exactly 100 rows?

解决方案

According to options and settings in the pandas docs, when you set display.max_rows to 100 and the DataFrame has more than 100 rows, pandas will still use the truncated view. Instead, the correct option is display.min_rows:

display.max_rows : int
    If max_rows is exceeded, switch to truncate view. Depending on
    `large_repr`, objects are either centrally truncated or printed as
    a summary view.

    'None' value means unlimited. Beware that printing a large number of rows
    could cause your rendering environment (the browser, etc.) to crash.

    In case python/IPython is running in a terminal and `large_repr`
    equals 'truncate' this can be set to 0 and pandas will auto-detect
    the height of the terminal and print a truncated object which fits
    the screen height. The IPython notebook, IPython qtconsole, or
    IDLE do not run in a terminal and hence it is not possible to do
    correct auto-detection.
    [default: 60] [currently: 60]
...
display.min_rows : int
    The numbers of rows to show in a truncated view (when `max_rows` is
    exceeded). Ignored when `max_rows` is set to None or 0. When set to
    None, follows the value of `max_rows`.
    [default: 10] [currently: 10]
import pandas as pd

df = pd.DataFrame({"col": list(range(1460))})
pd.set_option('display.min_rows', 100)
df

screenshot of min_rows=100

To display all rows, you can set pd.set_option('display.max_rows', None):

pd.set_option('display.max_rows', None)
df

screenshot of max_rows=None

To display only the first 100 rows, you can use .head(100):

pd.set_option('display.max_rows', None)  # or set to 100
df.head(100)

screenshot of .head(100)

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章