pandas
Omgaan met categorische variabelen
Zoeken…
Eenmalige codering met `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
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow