ComenzarEmpieza gratis

Dummy variables

In the last exercise of the course, you will prepare your data for modeling by dummy encoding your non-numeric columns. For example, if you have a column of gender values, 'Male' and 'Female', you want separate columns that tell you whether the observation is from a 'Male' or a 'Female'. This process of creating dummy variables is also called one-hot encoding.

You can use the get_dummies() function from pandas to convert the non-numeric columns into dummy variables.

df_new = pd.get_dummies(df)

We've subsetted the flights DataFrame to create flights_sub to make it easier to see what is happening.

Este ejercicio forma parte del curso

Python for R Users

Ver curso

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Look at the head of flights_sub
print(____)
Editar y ejecutar código