Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations

← All challenges
VC03 · Student attendance / study · ~10–15 min

Do longer sessions relate to better scores?

complete pairs · association · communication

Relationship view

The question

Explore the relationship between study hours and score without treating it as evidence of causation.

df Relationship view

Your inputs

df

One row is one learner’s study session and assessment. Hours and scores must stay paired; attendance is not an eligibility condition here.

Field meanings and units
submission_id
Attendance-submission identifier.
student
Learner label.
group
Comparison group.
hours
Study duration in hours.
score
Assessment score in points.
attended
Whether the learner attended.
date
Calendar date supplied as YYYY-MM-DD text unless the task states it is invalid.
df · first 5 of 20 rows
submission_idstudentgrouphoursscoreattendeddate
S001Learner 1A261false2026-04-01
S002Learner 2B574true2026-04-01
S003Learner 3A379true2026-04-02
S004Learner 4B7Nonetrue2026-04-02
S005Learner 5A468false2026-04-03
View all 20 rows
df · complete input
submission_idstudentgrouphoursscoreattendeddate
S001Learner 1A261false2026-04-01
S002Learner 2B574true2026-04-01
S003Learner 3A379true2026-04-02
S004Learner 4B7Nonetrue2026-04-02
S005Learner 5A468false2026-04-03
S006Learner 6B682true2026-04-03
S007Learner 7ANone88true2026-04-04
S008Learner 8B157true2026-04-04
S009Learner 9A264false2026-04-05
S010Learner 10B586true2026-04-05
S011Learner 11A358true2026-04-06
S012Learner 12B784true2026-04-06
S013Learner 13A477false2026-04-07
S014Learner 14B673true2026-04-07
S015Learner 15A892true2026-04-08
S016Learner 16B152true2026-04-08
S017Learner 17A269false2026-04-09
S018Learner 18B576true2026-04-09
S019Learner 19A381true2026-04-10
S020Learner 20B787true2026-04-10

The editable setup in Your Python creates these inputs when you run it.

Your task · Do longer sessions relate to better scores?

Explore the relationship between study hours and score without treating it as evidence of causation.

pairsDataFramefigFigure

Deliverables

Make the outputs listed below. Use each name exactly as shown. Then choose Check answer.

Python name key

Teal outlines name table columns. Violet left rules name Python objects. Dotted rules mark syntax, functions and parameters. Use each name exactly as shown.

  1. Complete pairsOutputpairsDataFrame
    1. Create pairs with hours and score only, keeping rows where both are known in their original row order.
  2. FigureOutputfigFigure
    1. Create fig showing one point for each complete hours/score pair, with hours on the horizontal axis and score on the vertical axis.
    2. Add a meaningful title and measure labels
    3. Display the figure.

    Identify Hours and Score on the appropriate axes; extra wording is welcome.

Data policy Keep all supplied source tables unchanged. Work on separate outputs.

Help Hints & explained solution

Choose the amount of help you need. Opening one hint does not reveal the others.

Hint 1 — Think

Must both coordinates come from the same learner?

Hint 2 — Tools

dropna(), Axes.scatter() or sns.scatterplot()

Revisit: Drop missing rows · Scatter plot · Finish a chart properly

Hint 3 — Approach

Keep complete pairs and represent each learner’s two measurements together.

Explained solution

Add these lines below # Your work in the editor. The supplied input setup is already there.

pairs = df[['hours', 'score']].dropna()
fig, ax = plt.subplots()
ax.scatter(pairs.hours, pairs.score)
ax.set(title='Study hours and score', xlabel='Hours', ylabel='Score')
fig.tight_layout()
plt.show()
View supplied setup

This code is already at the top of the editor.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

# Supplied input: df (20 rows)
df = pd.DataFrame(
    [
        ('S001', 'Learner 1', 'A', 2, 61, False, '2026-04-01'),
        ('S002', 'Learner 2', 'B', 5, 74, True, '2026-04-01'),
        ('S003', 'Learner 3', 'A', 3, 79, True, '2026-04-02'),
        ('S004', 'Learner 4', 'B', 7, None, True, '2026-04-02'),
        ('S005', 'Learner 5', 'A', 4, 68, False, '2026-04-03'),
        ('S006', 'Learner 6', 'B', 6, 82, True, '2026-04-03'),
        ('S007', 'Learner 7', 'A', None, 88, True, '2026-04-04'),
        ('S008', 'Learner 8', 'B', 1, 57, True, '2026-04-04'),
        ('S009', 'Learner 9', 'A', 2, 64, False, '2026-04-05'),
        ('S010', 'Learner 10', 'B', 5, 86, True, '2026-04-05'),
        ('S011', 'Learner 11', 'A', 3, 58, True, '2026-04-06'),
        ('S012', 'Learner 12', 'B', 7, 84, True, '2026-04-06'),
        ('S013', 'Learner 13', 'A', 4, 77, False, '2026-04-07'),
        ('S014', 'Learner 14', 'B', 6, 73, True, '2026-04-07'),
        ('S015', 'Learner 15', 'A', 8, 92, True, '2026-04-08'),
        ('S016', 'Learner 16', 'B', 1, 52, True, '2026-04-08'),
        ('S017', 'Learner 17', 'A', 2, 69, False, '2026-04-09'),
        ('S018', 'Learner 18', 'B', 5, 76, True, '2026-04-09'),
        ('S019', 'Learner 19', 'A', 3, 81, True, '2026-04-10'),
        ('S020', 'Learner 20', 'B', 7, 87, True, '2026-04-10'),
    ],
    columns=['submission_id', 'student', 'group', 'hours', 'score', 'attended', 'date'],
)

Why these steps exist

  • Dropping incomplete pairs keeps each horizontal coordinate attached to its own vertical coordinate.
  • The scatter shows association in these records. It does not establish that more study causes a particular score.

Another valid approach

Matplotlib and Seaborn point plots are accepted when each complete hours/score pair is represented once.

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. Named outputs appear below when you run. Display charts with plt.show().

Python starts when you open a lesson.

Output

Run your code to see what Python returns.