Impute categorical missing values in scikit-learn

后端 未结 10 1411
清歌不尽
清歌不尽 2020-11-30 16:55

I\'ve got pandas data with some columns of text type. There are some NaN values along with these text columns. What I\'m trying to do is to impute those NaN\'s by skle

10条回答
  •  既然无缘
    2020-11-30 17:31

    sklearn.impute.SimpleImputer instead of Imputer can easily resolve this, which can handle categorical variable.

    As per the Sklearn documentation: If “most_frequent”, then replace missing using the most frequent value along each column. Can be used with strings or numeric data.

    https://scikit-learn.org/stable/modules/generated/sklearn.impute.SimpleImputer.html

    impute_size=SimpleImputer(strategy="most_frequent") 
    data['Outlet_Size']=impute_size.transform(data[['Outlet_Size']])
    

提交回复
热议问题