Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Visualise lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Choose and build · V35 · 8 MIN

Choose a chart for the question

Match the question and variable types before writing plotting code.

Exercises within this concept

  1. FollowFollow a chart choiceCurrent exercise
  2. ChangeDistinguish a distribution question
  3. TransferSelect a chart for a new question

Understand the idea

Choose a chart from the question and the types of data. Decide what each mark should represent before writing plotting code.

Concept sketch: one point per pair of numeric valuesyxone point per pair of numeric values
Two numeric variables
Concept sketch: adjacent bins count numeric observationsCount02468adjacent bins count numeric observations
One numeric distribution
Concept sketch: bar height = number of rowsCount04A2B3Cbar height = number of rows
Category frequencies
Concept sketch: connect observations in time order1234Dayconnect observations in time order
Change over time

A small example

“Do longer study times go with higher scores?” compares two measurements per person, so one point per person is useful.

Follow the code

Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.

"scatter"

What each part does

"scatter"
relationship between two numeric variables
"histogram"
distribution of one numeric variable
"counts"
frequency of category labels
"line"
change along an ordered time sequence

Your inputs

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

Study club · 8 synthetic rows
studentclubhoursscoregroup
AriArt152A
BoCode371A
CyArt265B
DeeCode482B
EliArt589A
FloCode376A
GusArt693B
HanCode261B

Your task · Follow

  1. Using df, which chart would help ask whether students who study longer tend to score higher?
  2. Write "scatter", "histogram", "counts" or "line" as your final Python string.
Hint

Identify the two numeric variables.

Reveal solution

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

"scatter"
Your task · Follow
  1. Using df, which chart would help ask whether students who study longer tend to score higher?
  2. Write "scatter", "histogram", "counts" or "line" as your final Python string.

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 a value by leaving it on the final line.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.