开始使用免费开始使用

用百分位数填补缺失值

在本练习中,您将继续练习填补缺失值。不同于上个练习,这一次您将使用百分位数替代平均值来进行填补。使用百分位数能得到更为保守的填补结果。用百分位数为某一列填补缺失值的一般步骤如下:

  • 从目标列中移除缺失值。
  • 然后计算该列非缺失数值的第 70 个百分位数。
  • 第 70 个百分位的"较差值"取决于您计算百分位数的列含义:
    • 例如,资产越多通常越好,因此资产少更"差"。资产的第 70 个百分位"较差值"其实就是资产的第 30 个百分位数。
    • 相应地,负债越多通常越差。因此,负债的第 70 个"较差值"就是它的第 70 个百分位数。

pandas 已使用别名 pd 导入,NumPy 已使用别名 np 导入。已为您加载一个名为 datasetpandas 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)
编辑并运行代码