调用函数 DataFrame.info() 时 Spyder 或 Pandas 的行为不正确

问题描述 投票:0回答:1

我正在使用 Spyder。用 Pandas 创建一些数据框:

import pandas as pd
import numpy.random as npr
npr.seed(0)
df = pd.DataFrame(npr.randint(1, 10, size=(3,4)))

使用时出现奇怪的行为

df.info()
:

dfi = df.info()

打印结果:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype
---  ------  --------------  -----
 0   0       3 non-null      int32
 1   1       3 non-null      int32
 2   2       3 non-null      int32
 3   3       3 non-null      int32
dtypes: int32(4)
memory usage: 180.0 bytes

并且变量被赋值

None

我怀疑包损坏,重新安装了pandas和spyder,结果还是一样。在痛苦地重置 miniconda 之前,我想知道这是否可以解决,或者至少可以通过一些测试来理解。

python pandas debugging spyder
1个回答
0
投票

其原因

print(df.info())
提供了df的简洁摘要,包括其索引dtype、列类型等,并且它不返回任何内容。这就是为什么当你打印时它会返回
None

© www.soinside.com 2019 - 2024. All rights reserved.