Scikit-learn label binarizer with support for missing values
import pandas as pd
import sklearn_dummies as skdm
df = pd.DataFrame(['A', 'B', None, 'A'], columns=['val'])
df_dummy = skdm.DataFrameDummies().fit_transform(df)
Result:
val_A | val_B | |
---|---|---|
0 | 1.0 | 0.0 |
1 | 0.0 | 1.0 |
2 | NaN | NaN |
3 | 1.0 | 0.0 |
Sklearn-dummies is available in PyPI. Install via pip:
pip install sklearn_dummies