pandas Dealing with categorical variables One-hot encoding with `get_dummies()`


Example

>>> df = pd.DataFrame({'Name':['John Smith', 'Mary Brown'],
                     'Gender':['M', 'F'], 'Smoker':['Y', 'N']})
>>> print(df)
  Gender        Name Smoker
0      M  John Smith      Y
1      F  Mary Brown      N
>>> df_with_dummies = pd.get_dummies(df, columns=['Gender', 'Smoker'])
>>> print(df_with_dummies)
         Name  Gender_F  Gender_M  Smoker_N  Smoker_Y
0  John Smith       0.0       1.0       0.0       1.0
1  Mary Brown       1.0       0.0       1.0       0.0