【发布时间】:2021-09-23 18:32:46
【问题描述】:
统计手机制造商
top3 = df_clean.info()['Handset Manufacturer'].value_counts().head(3)
top3
【问题讨论】:
-
欢迎来到 Stackoverflow!请阅读此stackoverflow.com/help/minimal-reproducible-example
标签: python-3.5
统计手机制造商
top3 = df_clean.info()['Handset Manufacturer'].value_counts().head(3)
top3
【问题讨论】:
标签: python-3.5
2个问题:一个问题是你需要定义df_clean变量应该指向什么数据,比如:
import pandas as pd
df_clean = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df_clean.info()
输出:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 3 entries, 0 to 2
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 A 3 non-null int64
1 B 3 non-null int64
dtypes: int64(2)
memory usage: 176.0 bytes
另一个问题是pandas.DataFrame.info 方法返回None,所以你无法从df_clean.info() 下标(就像你在代码中所做的df_clean.info()['Handset Manufacturer'])。尝试删除 .info() 部分,例如:
top3 = df_clean['A'].value_counts().head(3)
print(top3)
输出:
0 1
1 2
2 3
Name: A, dtype: int64
【讨论】: