Total members of the chosen clubs

Write code · Basic · §11.2 Data, widgets, and filters

The table clubs holds the members of three clubs in January and February. Put a multiselect widget (st.sidebar.multiselect) labeled Club in the sidebar. Its choices are Photo, Band, and Chess, and all three are chosen at the start.

Store only the rows of the chosen clubs in view. If nothing is chosen, show st.warning("Pick at least one club.") and stop with st.stop(). If rows remain, show the total members in a metric labeled Members.

Target figure for Total members of the chosen clubs
Target figure

Starter code

import pandas as pd
import streamlit as st

clubs = pd.DataFrame({
    "club": ["Photo", "Photo", "Band", "Band", "Chess", "Chess"],
    "month": [1, 2, 1, 2, 1, 2],
    "members": [12, 15, 20, 19, 8, 9],
})
st.title("Club dashboard")

# Write your code here

Solve 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.