import pandas as pd
import numpy as np
X = pd.DataFrame({'Shape':['square', 'square', 'oval', 'circle', np.nan]})
X
Shape | |
---|---|
0 | square |
1 | square |
2 | oval |
3 | circle |
4 | NaN |
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(strategy='most_frequent')
imputer.fit_transform(X)
array([['square'], ['square'], ['oval'], ['circle'], ['square']], dtype=object)
imputer = SimpleImputer(strategy='constant', fill_value='missing')
imputer.fit_transform(X)
array([['square'], ['square'], ['oval'], ['circle'], ['missing']], dtype=object)
© 2020 Data School. All rights reserved.