from sklearn import preprocessing
import numpy as np
X = [[1, 2], [np.nan, 4], [2, 6]]
y = [[np.nan, 4], [1, 3], [2, 4]]
imp = preprocessing.Imputer(missing_values='Nan', strategy='mean')
imp.fit(X)
print(imp.transform(X))
print(imp.transform(y))