An hourly wait-time line that joins two days of rows as they are
Code review · Medium · §9.2 Scatter plots, tooltips, and averages
The table queues holds the wait times (minutes) for two theme park rides (Coaster and Wheel), measured every hour on Saturday and Sunday. To draw the average wait per hour, the AI draft passed this table to px.line() as it is.
Fix it by changing two lines or fewer so that each ride gets a line that joins the two-day average at each hour (hour). Grading changes the wait times and draws the chart again.
Code to fix
import pandas as pd
import plotly.express as px
queues = pd.DataFrame({
"day": ["Sat"] * 8 + ["Sun"] * 8,
"ride": (["Coaster"] * 4 + ["Wheel"] * 4) * 2,
"hour": [10, 11, 12, 13] * 4,
"minutes": [30, 52, 41, 25, 18, 35, 44, 29, 34, 48, 45, 21, 20, 31, 40, 33],
})
fig = px.line(queues, x="hour", y="minutes", color="ride", markers=True,
title="Average wait by hour")
fig.update_xaxes(dtick=1)
fig.show()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.