Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Visualise lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Optional · models and matrices · VR5 · 12 MIN

Review · models and matrices

Task 1 · Retrieve and combine

Exercises within this concept

  1. Task 1Retrieve and combineCurrent exercise
  2. Task 2Retrieve and combine
  3. Task 3Retrieve and combine
  4. Task 4Retrieve and combine
Task 1 · Daily site visits · paired observations

From the supplied repeated df visits, show replicate B over day as a line with markers and no aggregation.

The editable setup on the right creates df. Run executes the setup and your work from top to bottom.

Your requirements

  1. This report follows one replicate, not a mean across replicates.
  2. Chart: title "Daily site visits · paired observations"; x "day"; y "visits".

Your inputs

Daily site visits · paired observations · 8 synthetic rows
dayvisitsreplicate
112A
114B
216A
218B
314A
316B
420A
422B

Revisit the concept lesson →

Remember the idea

Concept sketch: line = mean; band = ±1 SD at each xline = mean; band = ±1 SD at each x

When several rows share an x value, a line can summarize them or follow one repeated measurement series.

A small example

At day 1, replicates A=4 and B=8 have mean 6. Selecting replicate A instead plots its observed value 4.

What each choice does
Code or choiceMeaning
estimator="mean"One average y at each x.
errorbar="sd"Show spread around that average using one standard deviation.
estimator=NoneDo not aggregate repeated x values; filter to one replicate to follow its trajectory.
Hint

Choose the observations first, then map the requested measurements to the chart.

Reveal solution

One way to do it. Keep any supplied setup in the editor and use this in the Your work section.

import matplotlib.pyplot as plt
import seaborn as sns

fig, ax = plt.subplots(figsize=(6, 4))
selected = df[df["replicate"] == "B"]
sns.lineplot(data=selected, x="day", y="visits", estimator=None, marker="o", ax=ax)
ax.set(title="Daily site visits · paired observations", xlabel="day", ylabel="visits")
fig.tight_layout()
plt.show()
Your task · Task 1
  1. From the supplied repeated df visits, show replicate B over day as a line with markers and no aggregation.
  2. This report follows one replicate, not a mean across replicates.
  3. Chart: title "Daily site visits · paired observations"; x "day"; y "visits".

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display charts with plt.show().

Python starts when you open a lesson.

Output

Run your code to see what Python returns.