Test and visualize conversion function
You've done the hard work of building your conversion rate function—now it's time to test it out! Automating your analyses can be time-consuming up front, but this is where it all pays off.
In this exercise, you'll see how quickly you can calculate the conversion rate. A task that in previous lessons took multiple steps. By automating the repetitive parts of your work, you'll be able to spend more time doing complex analyses.
This exercise is part of the course
Analyzing Marketing Campaigns with pandas
Exercise instructions
- Use your
conversion_rate()
function to calculate the conversion rate inmarketing
bydate_served
andage_group
and store your results inage_group_conv
. - Unstack
age_group_conv
at level equal to 1 and wrap that in a call topd.DataFrame()
to createage_group_df
. - Create a line chart to display your results from
age_group_df
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Calculate conversion rate by age_group
age_group_conv = ____(____, ['date_served', ____])
print(age_group_conv)
# Unstack and create a DataFrame
age_group_df = ____(age_group_conv.____)
# Visualize conversion by age_group
age_group_df____
plt.title('Conversion rate by age group\n', size = 16)
plt.ylabel('Conversion rate', size = 14)
plt.xlabel('Age group', size = 14)
plt.show()