因素關係與分佈

Python 的探索性資料分析

Izzy Weber

Curriculum Manager, DataCamp

教育程度:男性伴侶

divorce["education_man"].value_counts()
Professional    1313
Preparatory      501
Secondary        288
Primary          100
None               4
Other              3
Name: education_man, dtype: int64
Python 的探索性資料分析

探索類別關係

sns.histplot(data=divorce, x="marriage_duration", binwidth=1)
plt.show()

婚姻持續時間的長條圖

Python 的探索性資料分析

探索類別關係

sns.histplot(data=divorce, x="marriage_duration", hue="education_man", binwidth=1)
plt.show()

依 education_man 著色的婚姻持續時間長條圖

Python 的探索性資料分析

核密度估計(KDE)圖

sns.kdeplot(data=divorce, x="marriage_duration", hue="education_man")
plt.show()

設定 hue 為 education_man 的婚姻持續時間 KDE

Python 的探索性資料分析

核密度估計(KDE)圖

放大至 marriage_duration 為 0、hue 為 education_man 的婚姻持續時間 KDE

Python 的探索性資料分析

核密度估計(KDE)圖

sns.kdeplot(data=divorce, x="marriage_duration", hue="education_man", cut=0)
plt.show()

hue 為 education_man、cut 為 0 的婚姻持續時間 KDE

Python 的探索性資料分析

累積 KDE 圖

sns.kdeplot(data=divorce, x="marriage_duration", hue="education_man", cut=0, cumulative=True)
plt.show()

hue 為 education_man、cut 為 0 的婚姻持續時間累積分佈

Python 的探索性資料分析

結婚年齡與教育的關係

  • 結婚年齡與教育程度有關嗎?
divorce["man_age_marriage"] = divorce["marriage_year"] - divorce["dob_man"].dt.year
divorce["woman_age_marriage"] = divorce["marriage_year"] - divorce["dob_woman"].dt.year
Python 的探索性資料分析

含類別變數的散佈圖

sns.scatterplot(data=divorce, x="woman_age_marriage", y="man_age_marriage")
plt.show()

woman_age_marriage 與 man_age_marriage 的散佈圖

Python 的探索性資料分析

含類別變數的散佈圖

sns.scatterplot(data=divorce, 
                x="woman_age_marriage",
                y="man_age_marriage", 
                hue="education_man")
plt.show()

設定 hue 為 education_man 的 woman_age_marriage 與 man_age_marriage 散佈圖

Python 的探索性資料分析

一起來練習吧!

Python 的探索性資料分析

Preparing Video For Download...