0
0

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.

ヒストグラム

Last updated at Posted at 2020-12-19

量的変数の分布

シンプルなヒストグラム

matplotlib


import matplotlib.pyplot as plt
plt.hist(df['column1']) # 引数はcolumから選択
plt.xlabel('column1')
plt.ylabel('freq')
plt.show()

download.png

seaborn

import seaborn as sns

sns.set()
sns.distplot(df['column1'], kde=False, bins=10, color='blue')
# kernel density estimation(カーネル密度推定)

download.png

複数のヒストグラムを描画したい

・$X_n$が2値分類データ(binaryで0,1など)における、量的変数$Y$に対する分布

import seaborn as sns

df_0 = df[df["x"] == 0] # object型を指定したいときは =="object"
df_1 = df[df["x"] == 1]
sns.distplot(df_0["Y"], kde=False, bins=20, color="r")
sns.distplot(df_1["Y"], kde=False, bins=20, color="b")

download.png

質的変数の分布

カウントプロット

import seaborn as sns

sns.countplot(data=df,x="column2")

download.png

# カウントプロットを別のcolumnの値ごとに色分けする。
import seaborn as sns

sns.countplot(data=df,x="column2",hue="marital")

download-1.png

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?