March 2019
Beginner to intermediate
464 pages
10h 57m
English
The last two categorical variables that we are going to encode in this section are housing and loan. The housing variable has two unique values, 'yes' and 'no', and contains information on whether a customer has a housing loan. The other variable, loan, also has two unique values, 'yes' and 'no', and tells us whether a customer has a personal loan. We can easily encode these two variables by using the following code:
df['housing'] = df['housing'].apply(lambda x: 1 if x == 'yes' else 0)df['loan'] = df['loan'].apply(lambda x: 1 if x == 'yes' else 0)
As you can see, we are using the apply function to encode yes as 1 and no as 0 for both the housing and loan variables. For those categorical variables that ...
Read now
Unlock full access