OK I understood. After I used Imputer(missing_values='NaN', strategy='median', axis=1) imp.fit(X2) . I also had to write:
X2 = imp.fit_transform(X2) . The reason is because sklearn.preprocessing.Imputer.fit_transform returns a new array, it does not change the array of arguments
source share