LoginSignup
0
2

More than 3 years have passed since last update.

groupbyの使い方

Posted at

pythonでデータを処理する時に使うgroupbyの使い方を説明する

groupbyとは?

groupby関数を使うとデータをグループ分けできる

実装

#必要なライブラリー
import numpy as np
import padnas as pd
#データを読み込む
from sklearn.datasets import laod_iris
data=load_iris()
#データをデータフレーム化
data=pd.DataFrame(data=data.data,columns=data.feature_names)
#データのsepal length(cm)の平均を取り出す
d=data.groupby(["sepal length(cm)"])

実装例

d=data.groupby(["sepal length(cm)"]).mean()
#平均を求める
d=data.groupby(["sepal length(cm)"]).size()
#サイズを求める
d=data.groupby(["sepal length(cm)"]).get_groupby("setosa")
#sepal length(cm)の中でsetosaのみ取り出す
0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2