关于 pandas set option 有没有其他方法可以解决?

Is there another way to solve about pandas set option?

我正在分析数据框并想查看更详细的列表
但即使我从 google、
搜索了一些解决方案 我不明白为什么结果没有改变。 有什么问题吗??

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np

# Import data
df = df = pd.read_csv(r"C:\Users\Administrator\Desktop\medical.txt")

pd.set_option("display.max_rows", 50)
pd.set_option('display.max_columns', 15)

print(df)


          id    age  gender  height  weight  ap_hi  ap_lo  cholesterol  gluc  
0          0  18393       2     168    62.0    110     80            1     1   
1          1  20228       1     156    85.0    140     90            3     1   
2          2  18857       1     165    64.0    130     70            3     1   
3          3  17623       2     169    82.0    150    100            1     1   
4          4  17474       1     156    56.0    100     60            1     1   
     ...    ...     ...     ...     ...    ...    ...          ...   ...   
69995  99993  19240       2     168    76.0    120     80            1     1   
69996  99995  22601       1     158   126.0    140     90            2     2   
69997  99996  19066       2     183   105.0    180     90            3     1   
69998  99998  22431       1     163    72.0    135     80            1     2   
69999  99999  20540       1     170    72.0    120     80            2     1    

如果有办法显示足够多的列

pd.set_option('display.width',1000)
or
pd.set_option('display.width',None)

但对于行,您可能只使用

df.head(50) 
or
df.tail(50)

或跟随 DisplayAll

pd.set_option("display.max_rows", None)

为什么设置没用:

第二个参数不是最大可查看行数,而是模板内部参数

  • 代码如下:
set_option = CallableDynamicDoc(_set_option, _set_option_tmpl)

CallableDynamicDoc:

class CallableDynamicDoc:
    def __init__(self, func, doc_tmpl):
        self.__doc_tmpl__ = doc_tmpl
        self.__func__ = func
 
    def __call__(self, *args, **kwds):
        return self.__func__(*args, **kwds)
 
    @property
    def __doc__(self):
        opts_desc = _describe_option("all", _print_desc=False)
        opts_list = pp_options_list(list(_registered_options.keys()))
        return self.__doc_tmpl__.format(opts_desc=opts_desc, opts_list=opts_list)

查看https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html“常用选项”一章。

您可以看到,如果“max_rows”小于数据框中的总行数,那么它会像您的结果一样显示。

下面是我给你的link中有趣部分的复制过去: