slearn 缺失值处理器: Imputer

class sklearn.preprocessing.Imputer(missing_values=’NaN’, strategy=’mean’, axis=0, verbose=0, copy=True)

参数:

  • missing_values: integer or “NaN”, optional (default=”NaN”)
  • strategy : string, optional (default=”mean”)
    • The imputation strategy.
      • If “mean”, then replace missing values using the mean along the axis. 使用平均值代替
      • If “median”, then replace missing values using the median along the axis.使用中值代替
      • If “most_frequent”, then replace missing using the most frequent value along the axis.使用众数代替,也就是出现次数最多的数
  • axis: 默认为 axis=0
    • axis = 0, 按列处理
    • aixs =1 , 按行处理

说实话,我还是没太弄明白aixs的具体含义,总感觉在不同的函数中有不同的含义。。还是使用前查找一下官方文档吧,毕竟大多数时候处理的都是2维数组,文档中的参数很容易理解。
注意:

  1. Imputer 只接受DataFrame类型
  2. Dataframe 中必须全部为数值属性

所以在处理的时候注意,要进行适当处理。

  1. 数值属性的列较少,可以将数值属性的列取出来 单独取出来
import pandas as pd
import numpy as np

df=pd.DataFrame([["XXL", 8, "black", "class 1", 22],
["L", np.nan, "gray"
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值