遺漏值

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 中級預測分析

遺漏值虛擬變數(dummy)

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