首页 > 解决方案 > 如何让 python 不将数据帧描述分解成块?

问题描述


下面的代码将 df 描述输出到两个块中,尽管 display.max_rows 和 display.max_columns 设置为高值。
我想打印它没有休息。有什么办法吗?

import pandas as pd

pd.set_option('display.max_rows', 1000)
pd.set_option('display.max_columns', 1000)

data = {'Age': [20, 21, 19, 18],
        'Height': [120, 121, 119, 118],
        'Very_very_long_variable_name': [40, 71, 49, 78]
        }
df = pd.DataFrame(data)
print(df.describe().transpose())

标签: pythonpandastranspose

解决方案


尝试在顶部添加此设置:

pd.set_option('display.expand_frame_repr', False)

现在:

import pandas as pd
pd.set_option('display.expand_frame_repr', False)
pd.set_option('display.max_rows', 1000)
pd.set_option('display.max_columns', 1000)

data = {'Age': [20, 21, 19, 18],
        'Height': [120, 121, 119, 118],
        'Very_very_long_variable_name': [40, 71, 49, 78]
        }
df = pd.DataFrame(data)
print(df.describe().transpose())

输出:

                              count   mean        std    min     25%    50%     75%    max
Age                             4.0   19.5   1.290994   18.0   18.75   19.5   20.25   21.0
Height                          4.0  119.5   1.290994  118.0  118.75  119.5  120.25  121.0
Very_very_long_variable_name    4.0   59.5  17.935068   40.0   46.75   60.0   72.75   78.0

推荐阅读