A line that jumps back after joining two quarterly tables

Code review · Basic · §9.4 Exploring and checking

The monthly parcel counts at two post offices (Main and Station) arrived quarter by quarter and are stored in the tables q1 (January to March) and q2 (April to June). The AI draft put q2, which arrived first, in front, joined the two tables, and drew lines.

Change one line so that each post office gets a line that joins January to June in month order. Grading changes the parcel counts and the order of the months inside a table and draws the chart again.

Target figure for A line that jumps back after joining two quarterly tables
Target figure

Code to fix

import pandas as pd
import plotly.express as px

q1 = pd.DataFrame({
    "month": [1, 2, 3, 1, 2, 3],
    "office": ["Main"] * 3 + ["Station"] * 3,
    "parcels": [420, 400, 350, 390, 370, 320],
})
q2 = pd.DataFrame({
    "month": [4, 5, 6, 4, 5, 6],
    "office": ["Main"] * 3 + ["Station"] * 3,
    "parcels": [310, 290, 340, 280, 265, 300],
})
received = pd.concat([q2, q1])

fig = px.line(received, x="month", y="parcels", color="office", markers=True,
              title="Monthly parcels by post office")
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.