我有分类数据,其预览如下所示:
0 Laborers
1 Core staff
2 Laborers
3 Laborers
4 Core staff
5 Laborers
6 Accountants
7 Managers
8 NaN
9 Laborers
...up to 307511 rows
我想使用KNN方法估算null,nan值(大约有9000个缺失值),我为此使用Sklearn,但我无法这样做,还有其他方法可以做到吗?
我使用了以下代码:
import numpy as np
from sklearn.impute import KNNImputer
X = [data['column_name']]
imputer = KNNImputer(n_neighbors=2)
imputer.fit_transform(X)