DataFrameの作成
qiita.rb
df = pd.DataFrame({'Animal': ['Falcon', 'Falcon',
'Parrot', 'Parrot','Parrot'],
'Max Speed': [380., 370., 24., 26.,27.],'Annimal_ID': [1, 1,2,2,2]})
df
Groupby
同じグループに対して処理をしたいときに使用する。
平均
qiita.rb
#FalconやParrotのグループに対して同じ処理をしたいときに使用する
df.groupby(['Animal']).mean()
サイズを調べる・取得する
qiita.rb
#サイズを調べる
df.groupby(['Animal']).size()
qiita.rb
#サイズの取得
Falcon_num=df.groupby(['Animal']).size()['Falcon']
print(Falcon_num)
特定のグループのデータ取得
qiita.rb
#サイズの取得
#特定のグループのデータの取得
df.groupby(['Animal']).get_group('Falcon')