Pandas 如果指定为列表,为什么IPython.display.display会以不同的顺序渲染输出?

Pandas 如果指定为列表,为什么IPython.display.display会以不同的顺序渲染输出?,pandas,ipython,jupyter,Pandas,Ipython,Jupyter,请注意,df.info()是结果中的第三项。然而,这首先呈现信息的输出,然后呈现其余的项。如何让它按指定顺序打印输出 但是,如果我显式调用display(不带列表),它将正确呈现: def inspect_df(df): results = (df.head(), df.tail(), df.info(), df.describe(include='all'),) for result in results: display(result) df = pd.D

请注意,
df.info()
是结果中的第三项。然而,这首先呈现信息的输出,然后呈现其余的项。如何让它按指定顺序打印输出

但是,如果我显式调用display(不带列表),它将正确呈现:

def inspect_df(df):
    results = (df.head(), df.tail(), df.info(), df.describe(include='all'),)
    for result in results:
        display(result)

df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})

inspect_df(df)

这是因为
df.info()
除了打印信息外不返回任何内容,解决方法是将信息信息保存为字符串,然后将其保存在
结果中进行迭代

def inspect_df(df):
    display(df.head())
    display(df.tail())
    display(df.info())
    display(df.describe(include='all'))

df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})

inspect_df(df)

xy
0  1  4
1  2  5
2  3  6
xy
0  1  4
1  2  5
2  3  6
范围索引:3个条目,0到2
数据列(共2列):
x3非空int64
y 3非空int64
数据类型:int64(2)
内存使用:176.0字节
xy
计数3.0 3.0
平均2.05.0
标准1.01.0
最低1.04.0
25%    1.5  4.5
50%    2.0  5.0
75%    2.5  5.5
最高3.0 6.0
import io
buffer = io.StringIO()
df.info(buf=buffer)
info_string = buffer.getvalue()

def inspect_df(df):
    results = (df.head(), df.tail(), info_string , df.describe(include='all'),)
    for result in results:
        print(result)

df = pd.DataFrame({'x': [1, 2, 3], 'y': [4, 5, 6]})

inspect_df(df)
   x  y
0  1  4
1  2  5
2  3  6
   x  y
0  1  4
1  2  5
2  3  6
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
x    3 non-null int64
y    3 non-null int64
dtypes: int64(2)
memory usage: 176.0 bytes

         x    y
count  3.0  3.0
mean   2.0  5.0
std    1.0  1.0
min    1.0  4.0
25%    1.5  4.5
50%    2.0  5.0
75%    2.5  5.5
max    3.0  6.0