Created
February 2, 2019 18:36
-
-
Save GermanCM/ba6097fb6eab9232bf5ebaaf2389a861 to your computer and use it in GitHub Desktop.
Impute attributes from a dataframe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def imputeMissingValues(dataframe, desired_strategy, attributes_to_impute): | |
from sklearn.preprocessing import Imputer | |
for attr in attributes_to_impute: | |
values_ = dataframe[attr].values.reshape(-1, 1) | |
imp = Imputer(missing_values=np.nan, strategy=desired_strategy, axis=0) | |
imp.fit(values_) | |
transformed_values = imp.transform(values_) | |
dataframe.loc[:,attr] = transformed_values | |
return dataframe |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment