LoslegenKostenlos loslegen

Encoding categorical variables - one-hot

One of the columns in the volunteer dataset, category_desc, gives category descriptions for the volunteer opportunities listed. Because it is a categorical variable with more than two categories, we need to use one-hot encoding to transform this column numerically. Use pandas' pd.get_dummies() function to do so.

Diese Übung ist Teil des Kurses

Preprocessing for Machine Learning in Python

Kurs anzeigen

Anleitung zur Übung

  • Call get_dummies() on the volunteer["category_desc"] column to create the encoded columns and assign it to category_enc.
  • Print out the .head() of the category_enc variable to take a look at the encoded columns.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Transform the category_desc column
category_enc = pd.____(____)

# Take a look at the encoded columns
print(____)
Code bearbeiten und ausführen