欠損値

Pythonで学ぶ中級予測分析

Nele Verbiest

Senior Data Scientist @PythonPredictions

集計値による欠損値の置換(1)

donor_id age
5 -
3 25
2 36
8 40
1 26
Pythonで学ぶ中級予測分析

集計値による欠損値の置換(2)

donor_id age
5 38
3 25
2 36
8 40
1 26

平均年齢:38

Pythonで学ぶ中級予測分析

集計値による欠損値の置換(3)

donor_id max_donation
5 -
3 1 000 000
2 100
8 40
1 120

max_donationの平均:25 065

max_donationの中央値:110

Pythonで学ぶ中級予測分析

集計値による欠損値の置換(4)

donor_id max_donation
5 110
3 1 000 000
2 100
8 40
1 120

max_donationの平均:25 065

max_donationの中央値:110

Pythonで学ぶ中級予測分析

固定値による欠損値の置換(1)

donor_id sum_donations
5 130
3 10
2 -
8 40
1 120
Pythonで学ぶ中級予測分析

固定値による欠損値の置換(2)

donor_id sum_donations
5 130
3 10
2 0
8 40
1 120
Pythonで学ぶ中級予測分析

Pythonでの欠損値の置換

# Replace missing values by 0
replacement = 0
basetable["donations_last_year"] = 
    basetable["donations_last_year"].fillna(replacement)

# Replace missing values by mean replacement = basetable["age"].mean() basetable["age"] = basetable["age"].fillna(replacement)
Pythonで学ぶ中級予測分析

欠損値ダミー

    donor_id email
0     32770  [email protected]
1     32776  nan
2     32777  [email protected]
3     65552  nan
basetable["no_email"] = pd.Series(
                            [0 if email==email else 1 
                            for email in basetable["email"]])
      donor_id email                    no_email
0     32770  [email protected]   0
1     32776  nan                        1
2     32777  [email protected]   0
3     65552  nan                        1
Pythonで学ぶ中級予測分析

練習しましょう!

Pythonで学ぶ中級予測分析

Preparing Video For Download...