Szukaj…


Jednorazowe kodowanie za pomocą `get_dummies ()`

>>> 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


Modified text is an extract of the original Stack Overflow Documentation
Licencjonowany na podstawie CC BY-SA 3.0
Nie związany z Stack Overflow