THINK FIRST·CODE LATER

← All labs

Review AI-written cleaning code

Problem

An assistant produced this pandas code to compute "average PM2.5 per district per month" for CityPulse:

df = pd.read_csv("readings.csv")
df = df.dropna()
df["month"] = df["timestamp"].str[5:7]
df = df[df["pm25"] > 0]
monthly = df.groupby(["district", "month"]).mean()
monthly.to_csv("monthly.csv")
chart = alt.Chart(monthly).mark_line().encode(x="month", y="pm25", color="district")
  1. Find at least five problems (correctness, robustness, honesty).
  2. Rewrite the code correctly, with checks.
  3. List what you would report next to the chart.

Work it out on paper, in a document or here, then compare with the model answer. Your answer stays in your browser — it is never sent to or stored on the server.