Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Visualise lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Compare observations · VR2 · 12 MIN

Review · Compare observations

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
Task 1 · Daily site visits

Using df, how did visits change over days 2 through 5 inclusive?

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

Your requirements

  1. Connect those ordered observations with a line and markers, without aggregation.
  2. Chart: title "Daily site visits"; x "day"; y "visits".

Your inputs

Daily site visits · 5 synthetic rows
dayvisits
140
252
347
460
568

Revisit the concept lesson →

Remember the idea

Concept sketch: connect observations in time order1234Dayconnect observations in time order

A line connects measurements along an ordered axis such as time. Decide whether repeated times represent raw observations or a summary.

A small example

At times 1, 2, 3 with sales 4, 7, 5, the line follows those values in time order.

What each choice does
Code or choiceMeaning
estimator=NoneKeep raw observations rather than averaging values at the same x.
marker="o"Show a circular marker at each plotted observation.
sort=True (default)Seaborn sorts x before connecting. Matplotlib ax.plot connects in the supplied order.
Hint

An ordered time question supports connecting neighboring observations.

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["day"] >= 2) & (df["day"] <= 5)]
ax.plot(selected["day"], selected["visits"], marker="o")
ax.set(title="Daily site visits", xlabel="day", ylabel="visits")
fig.tight_layout()
plt.show()
Your task · Task 1
  1. Using df, how did visits change over days 2 through 5 inclusive?
  2. Connect those ordered observations with a line and markers, without aggregation.
  3. Chart: title "Daily site visits"; 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.