from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder()
enc.fit([[0, 0, 3], [1, 1, 0], [0, 2, 1], [1, 0, 2]])
enc.n_values_
enc.feature_indices_
enc.transform([[0, 1, 1]]).toarray()
How to binarize the values in a pandas DataFrame?