Skip to content

Instantly share code, notes, and snippets.

@sazio
Created August 29, 2020 12:11
Show Gist options
  • Save sazio/dc90bd9c7d1666e12c90c2b79936c60d to your computer and use it in GitHub Desktop.
Save sazio/dc90bd9c7d1666e12c90c2b79936c60d to your computer and use it in GitHub Desktop.
import pandas as pd
# Create a dataframe (categorical data)
df = pd.DataFrame([["a", "x"],
[np.nan, "y"],
["a", np.nan],
["b", "y"]], dtype="category")
imp = SimpleImputer(strategy="most_frequent")
print(imp.fit_transform(df))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment