Skip to content

Instantly share code, notes, and snippets.

@ChristopherDaigle
Last active June 1, 2020 03:55
Show Gist options
  • Save ChristopherDaigle/056cdb10602cfcff8c537b14ec4adc3a to your computer and use it in GitHub Desktop.
Save ChristopherDaigle/056cdb10602cfcff8c537b14ec4adc3a to your computer and use it in GitHub Desktop.
from sklearn.impute import KNNImputer
imputer = KNNImputer(n_neighbors=int(round(np.sqrt(df_1.shape[0]))))
df_1.reset_index(inplace = True, drop = True)
impute_df = df_1.drop(columns='release_date')
impute_df_filled = imputer.fit_transform(X=impute_df)
imputed_cols = list(df_1.drop(columns='release_date').columns)
df_impute = pd.DataFrame(data=impute_df_filled, columns=imputed_cols)
df_1_impute_fill = pd.concat([df_impute, df_1['release_date']], axis=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment