Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Explorations › Data detective › lesson 1 of 6

Load a real dataset

Every investigation starts by reading the data in and looking at it. Load a class's study records with Python and meet them in 3D.

A data detective's first job is not to calculate. It is to look. In this module you will investigate one dataset from start to finish: 40 students, how many hours each studied, how many hours they slept the night before and their test score. (The data is made up for practice.)

Each ball is a student. Hours studied run left to right, sleep runs front to back and score goes up. Turn the model: most balls form a rising cloud, but a few look wrong. Keep those in mind.

Read it with Python

Data usually arrives as a CSV file: comma-separated values, one row per line, with a header row naming the columns. Python's csv module reads it into a list of dictionaries, one per student.

First questions to ask

  • How many rows and columns are there?
  • What does one row mean? Here, one student.
  • What type is each column? Everything arrives as text, even numbers: '3.4' is a string until you convert it.
  • Are there gaps or strange values?

Three students have a missing value. The next lesson deals with them, and with two values that are present but impossible.

What to remember

  • Look at data before calculating anything.
  • CSV files are rows of comma-separated values with a header row.
  • csv.DictReader turns each row into a dictionary keyed by column name.
  • Values arrive as text; convert them to numbers before doing maths.
Next