A reading room app that stops when the file is missing or empty
Write code · Medium · §11.1 Running an app and the rerun model
This app reads seats.csv, which holds the number of reading room seats booked each day at a library. Its columns are date (the day) and seats (the seats booked). load_data() in the starter code reads the CSV next to the app file, and the title is already there. Write the following below it.
When seats.csv is missing, show st.error("Put seats.csv next to app.py.") and then call st.stop(). If the file exists but has only the header line and no rows, show st.error("seats.csv has no rows.") and stop. Otherwise, show the number of days and the total seats with st.caption() in the form Data: 3 days, 1,050 seats (the total with a thousands separator). Grading changes the CSV contents and also runs the app without the file and with only the header.
Starter code
from pathlib import Path
import pandas as pd
import streamlit as st
st.set_page_config(page_title="Reading room", layout="wide")
@st.cache_data
def load_data():
return pd.read_csv(Path(__file__).with_name("seats.csv"))
st.title("Reading room seats")
# Write your code hereFile seats.csv
date,seats
2026-04-06,212
2026-04-07,198
2026-04-08,240
2026-04-09,225
2026-04-10,187
2026-04-11,142Solve 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.