A period conversion rate from summed counts
Write code · Medium · §11.5 Editing and optional extensions
The table downloads holds, for each platform and day, the number of installs of a mobile app (installs) and how many of those people made a purchase (buyers). The starter code picks platforms and days in the sidebar and stores the chosen rows in view. Below it, put two metrics in the order Installs, Conversion.
Installs shows the total installs in the chosen range with a thousands separator (12,345). Conversion shows the conversion rate for the chosen period, that is, the total buyers ÷ the total installs × 100, with one decimal place and % (4.2%). It is not the mean of the daily conversion rates. Grading runs the app again with different widget values and different install and buyer counts.
Starter code
import pandas as pd
import streamlit as st
downloads = pd.DataFrame({
"day": [1, 2, 3, 4, 5, 6] * 2,
"platform": ["iOS"] * 6 + ["Android"] * 6,
"installs": [1200, 300, 800, 2500, 600, 1500, 2000, 900, 400, 1800, 3000, 700],
"buyers": [60, 30, 48, 100, 42, 75, 50, 36, 20, 54, 60, 35],
})
st.title("App downloads")
platforms = st.sidebar.multiselect("Platform", ["iOS", "Android"], default=["iOS", "Android"])
days = st.sidebar.slider("Day", 1, 6, (1, 6))
view = downloads[downloads["platform"].isin(platforms) & downloads["day"].between(days[0], days[1])]
if view.empty:
st.warning("Pick at least one platform.")
st.stop()
# Write your code hereSolve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.