March 2019
Beginner to intermediate
464 pages
10h 57m
English
The first thing we are going to do is encode the response variable Response. We are going to encode Yes values with 1s and No values with 0s. Take a look at the following code:
df['Engaged'] = df['Response'].apply(lambda x: 1 if x == 'Yes' else 0)
As you can see from this code, we are using the apply function of the pandas DataFrame to apply our lambda function on the Response column, so that it encodes Yes values with 1 and No values with 0. We then store these encoded values in a newly-created column, Engaged. In order to get the overall response or engagement rate using this newly-created column, you can use the following code:
tdf['Engaged'].mean()
The overall engagement rate looks as follows:
Read now
Unlock full access