我初始化了一个df,如下所示:
import numpy as np
import pandas as pd
df = pd.read_csv('pokemon_data.csv')
df
为此df.info数据集运行www.example.com():
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 800 entries, 0 to 799
Data columns (total 12 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 # 800 non-null int64
1 Name 800 non-null object
2 Type 1 800 non-null object
3 Type 2 414 non-null object
4 HP 800 non-null int64
5 Attack 800 non-null int64
6 Defense 800 non-null int64
7 Sp. Atk 800 non-null int64
8 Sp. Def 800 non-null int64
9 Speed 800 non-null int64
10 Generation 800 non-null int64
11 Legendary 800 non-null bool
dtypes: bool(1), int64(8), object(3)
memory usage: 69.7+ KB
接下来我使用groupby函数来计算平均值,使用以下代码:
a = df.groupby(['Type 1']).mean()
display(a)
显示错误:
我期待看到这样的东西:
1条答案
按热度按时间6qftjkof1#
把它改成这个应该对你有帮助。
您可以尝试提及要计算其均值的列名。