March 2020
Beginner to intermediate
352 pages
8h 40m
English
Often, we need to convert a categorical variable into some dummy matrix. Especially for statistical modeling or machine learning model development, it is essential to create dummy variables. Let's get started:
df = pd.DataFrame({'gender': ['female', 'female', 'male', 'unknown', 'male', 'female'], 'votes': range(6, 12, 1)})df
The output of the preceding code is as follows:

So far, nothing too complicated. Sometimes, however, we need to encode these values in a matrix form with 1 and 0 values.
Read now
Unlock full access