以百分位數補值遺漏值
在這個練習中,你會繼續練習補值遺漏值。不過,與上一題不同之處在於,你將以百分位數取代平均數來進行補值。使用百分位數能得到較為保守的補值結果。以百分位數為基礎,對某欄位的遺漏值進行補值的一般步驟如下:
- 先把該欄位中的遺漏值移除。
- 接著計算該欄位數值的第 70 百分位數(以移除遺漏值後的資料計算)。
- 第 70 百分位的「較差值」取決於你計算百分位數的欄位性質:
- 例如,資產越多通常越好,因此資產偏少才是「較差」。資產的第 70 百分位「較差值」其實就是資產的第 30 百分位數。
- 類似地,負債越多通常越不好。所以負債的第 70 百分位「較差值」就是它的第 70 百分位數。
pandas 已以別名 pd 載入,NumPy 已以別名 np 載入。已為你載入名為 dataset 的 pandas DataFrame。它包含欄位 "Total Current Liabilities",其中有部分遺漏值。
本練習屬於課程
使用 Python 分析財務報表
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Impute missing value with 70th percentile non-missing values of company
impute_by_company = ___
# Impute missing value with 70th percentile non-missing values of industry
impute_by_comp_type = ____
print(impute_by_company)
print(impute_by_comp_type)