0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pandas 統計量

Last updated at Posted at 2021-03-18
import pandas as pd
import numpy as np
df = pd.DataFrame({
    "category1" : ["A","A","A","B","B","B"],
    "column1" : np.array([5,4,6,9,11,13])
})

スクリーンショット 2021-03-19 0.11.23.png

統計量

df.describe()

スクリーンショット 2021-03-19 0.12.00.png

column1はcategoryでAとBに別れているが区別なく統計量が出るのは不便。

groupby関数

category A,B で区別して統計量を得る。

# category1でgroupを作る
group = df.groupby("category1")
# groupごとに関数処理する
print(group.mean()) # 平均

print(group.std(ddof = 1)) # 標準偏差

スクリーンショット 2021-03-19 0.19.59.png

group.describe() # groupごとに統計量の一括表示

スクリーンショット 2021-03-19 0.21.15.png

地道に取り出す

# Aを取り出す
df_A = df[df["category1"] == "A"]
# mean関数に通す
df_A["column1"].mean()

groupby便利。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?