Exercise

Ordinal encoding of a categorical column

Imputing categorical values involves a few additional steps over imputing numerical values. You need to first convert them to numerical values as statistical operations cannot be performed on strings.

You will use the user profile dataset which contains customer preferences and choices recorded by a restaurant. It contains only categorical features. In this exercise, you will convert the categorical column 'ambience' to a numerical one using OrdinalEncoder from sklearn. The DataFrame has been loaded for you as users. The function OrdinalEncoder() has also been loaded.

The head() and tail() of users DataFrame has been printed for you.

Instructions

100 XP
  • Create the ordinal encoder object and assign it to ambience_ord_enc.
  • Select the non-missing values of the 'ambience' column in users.
  • Reshape ambience_not_null to shape (-1, 1).
  • Replace the non-missing values of ambience with its encoded values.