A food truck app that keeps the chosen menus and days
Fill in the blanks · Basic · §11.2 Data, widgets, and filters
The table truck holds how many of each menu item a food truck sold on days 1 to 7 (it was closed on days 4 and 7). Day in the sidebar is a slider that picks a range from 1 to 7 and starts with the whole range, 1 to 7. Fill in the three blanks so that view keeps only the rows for the chosen menus on the chosen days (both ends included). Grading runs the app again with different widget values.
Code with blanks
import pandas as pd
import streamlit as st
truck = pd.DataFrame({
"day": [1, 1, 2, 2, 3, 3, 5, 5, 6, 6],
"menu": ["Taco", "Waffle"] * 5,
"sold": [42, 18, 37, 25, 51, 22, 46, 30, 60, 41],
})
st.title("Food truck")
menus = st.sidebar.multiselect("Menu", ["Taco", "Waffle"], default=["Taco", "Waffle"])
days = st.sidebar.slider("Day", 1, 7, ____)
keep = truck["menu"].isin(menus) ____ truck["day"].____
view = truck[keep]
if view.empty:
st.warning("Nothing sold. Pick a menu or other days.")
st.stop()
st.caption(f"{len(view)} rows, {view['sold'].sum()} sold")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.