Track 14 · Practical Data Analysis · Lesson 1 of 11

Importing data

Import a CSV file, read the import check, and verify that what was loaded matches the file before analysing anything.

25 minIntermediate8 graded exercisesFree

A marketing manager sends you an export of 700 customer records and asks for the average annual spend by city by Thursday. Before any average, you need to know what actually arrived: how many rows, which columns, which types — and which problems the import quietly let through.

Most business data reach an analyst as a CSV file (comma-separated values): plain text in which each line is one record and the values in a line are separated by a delimiter. The first line is usually a header that names the columns.

A CSV has no types, no formatting and no formulas — just text. Everything else (this column is a number, that one is a date, this blank means missing) is decided by the software that reads the file. That is why importing is an analytical step, not a clerical one.

Worked example

Reading a small CSV by hand

A file contains these four lines:

customer_id,city,annual_spend_sar,note
C0001,Riyadh,4679.64,
C0002,"Al Khobar",NA,"called, no answer"
C0003,jeddah,1250,unknown

How many records and columns are there, and what does each cell become?

  1. Header. The first line names four columns: customer_id, city, annual_spend_sar, note. It is not a record, so there are 3 records, not 4.

  2. Delimiter and quotes. Values are separated by commas. A value that itself contains a comma must be wrapped in double quotes: "called, no answer" is one value. Without the quotes the line would have five values and everything after the comma would shift one column to the right.

  3. Missing values. C0001's note is empty and C0002's spend is NA: both are standard ways of writing missing. But C0003's note unknown is just a word — software that does not know your conventions keeps it as text.

  4. Spellings. Riyadh and jeddah differ in capitalisation. The file does not care; your city counts will, unless you standardise them later.

3 records × 4 columns. Two cells are missing (one blank, one NA); unknown survives as text and jeddah as a separate spelling — problems the import itself will not fix.

## How the lab imports a file

The lab has an Import CSV… button. It reads .csv, .tsv and .txt files only — an Excel workbook must first be saved as CSV (in Excel: File → Save As → CSV UTF-8). The file is parsed in your browser and stored only in this browser; it is never uploaded to Statistics Quest's servers, and clearing your site data removes it.

StepWhat happensWhat to check
Size limitsUp to 5 MB, 50 000 rows, 200 columns, 1 000 characters per cellSplit or sample larger files first
DelimiterDetected from the first lines: comma, semicolon or tabColumns line up in the Data tab
HeaderFirst row = column names, turned into lowercase_with_underscores ("Annual Spend (SAR)" → annual_spend_sar)Names are unique and meaningful
SpacesLeading and trailing spaces are trimmed from every value" Riyadh " becomes "Riyadh"; "RIYADH" stays different
Missing valuesBlank, NA, N/A, nan, null, none, ".", "-", #N/A and "?" (any capitalisation) become missingOther placeholders ("unknown", "999", "-1") are NOT recognised
TypesA column is numeric if at least 95% of its non-missing values are numbers; ISO dates (2024-03-15) are dates; true/false/yes/no are booleans; few distinct values → category, otherwise textInferred types in the Columns table
SafetyNothing is evaluated: a cell such as =SUM(A1) stays plain text—
What the lab does when it reads a CSV file

Dataset

Customer records (messy)

700 rows · one row = one customer record (some customers appear twice) · synthetic data

CustomerSignup dateCitySegmentAge (years)Annual spend (SAR)Referral sourceEmail opt-in
C00012024-02-28RiyadhSmall business31571670Advertisementtrue
C00022021-07-15JeddahIndividual204679.64Friendtrue
C00032024-08-12DammamSmall business303027.49Advertisementfalse
C00042022-11-14RiyadhIndividual345440.72Searchfalse
C00052022-12-01RiyadhIndividual471382.89Social mediafalse
C00062023-11-01KhobarIndividual374162.73Store visitfalse
C00072022-12-06JeddahIndividual364146.99Friendfalse
C00082023-10-20RiyadhIndividual242789.46Searchfalse

The (synthetic) customer export used throughout this track. One row is meant to be one customer — but some customers appear twice. Look at the first row's annual spend: 571 670 SAR for a homeware shop is suspicious (it will turn out to be recorded in halalas).

A first look after every import

  1. Count rows and columns and compare them with what the sender says the file contains.
  2. Read the import check: missing-value tokens per column, values that did not fit the inferred type, rows with the wrong number of values.
  3. Check the inferred types in the Data tab's Columns table — is every quantity numeric, every code a category or identifier?
  4. Check the Missing and Distinct columns of the profile: an ID column should have as many distinct values as rows; a city column should have a handful.
  5. Sort and scroll: sort each numeric column to see its smallest and largest values; open the filter list of each category to see its spellings.

Quick check

The Data tab shows 700 rows and the customer_id column has 679 distinct values. What is the most likely explanation?

Exercises

The lesson is complete when every exercise is answered correctly. Hints are free; viewing a worked solution before solving means the exercise won't count towards mastery.

0 of 8 exercises correct (not saved — sign in to keep your progress)

Exercise 1 · Guided, difficulty 1 of 3

Which cells become missing?

Not started

A till system exports this CSV file:

order_id,channel,amount_sar
R101,unknown,48
R102,n/a,212
R103,n/a,259
R104,Store,666
R105,#N/A,749
R106,?,852
R107,Store,450
R108,null,340
R109,Phone,72
R110,Store,234
R111,NA,659
R112,Store,667

You import it into the lab. How many values of channel will the import check report as missing?

Exercise 2 · Application, difficulty 1 of 3

What arrived?

Not started

Open customers_messy in the lab (Data tab). Use the row count and the Columns table to answer: how many rows (records), how many columns, and how many distinct values does customer_id have?

Data: customers_messy · Open in the lab to explore and calculate.

Exercise 3 · Practice, difficulty 1 of 3

Missing token or real value?

Not started

Each item is the full content of one cell in a CSV file you import into the lab. Will the lab read it as missing, or keep it as a value?

(an empty cell)
N/A
null
#N/A
?
unknown
0
-1 in an age column
N.A.

Exercise 4 · Application, difficulty 2 of 3

Download, import, compare

Not started

On its dataset page, customers_messy can be downloaded as a CSV file. Suppose you download it and import that file into the lab, then read the import check and the Columns table.

  1. How many referral_source values does the import check report as missing?
  2. How many distinct city spellings does the imported table have (missing excluded)?

Remember what the import does to spaces, and that the download protects text cells that begin with -, =, + or @ by putting an apostrophe in front of them (so a spreadsheet cannot run them as formulas).

Data: customers_messy · Open in the lab to explore and calculate.

Exercise 5 · Interpretation, difficulty 2 of 3

A semicolon file with decimal commas

Not started

A supplier's system exports prices like this:

sku;price;stock
A-101;12,5;40
A-102;8,75;12
A-103;19,9;0

You import the file into the lab. What happens to the price column?

Choose one

Exercise 6 · Practice, difficulty 1 of 3

From workbook to checked table

Not started

A colleague emails you an Excel workbook of customer records. Put the steps in a sensible order.

Put the steps in order (use the arrows)

  1. 1Import the CSV into the lab with Import CSV…
  2. 2Sort numeric columns and list category spellings to look for suspicious values
  3. 3Check the inferred type, missing count and distinct count of every column
  4. 4Read the import check: missing tokens, values that did not fit the type, rows of the wrong length
  5. 5Compare the row and column counts with what the colleague says the file contains
  6. 6Open the workbook and save the relevant sheet as CSV UTF-8

Exercise 7 · Interpretation, difficulty 1 of 3

What is true about the lab's import?

Not started

Select all statements that are true about importing your own file into the lab.

Select all that apply

Exercise 8 · Interpretation, difficulty 2 of 3

Note what the import check missed

Not started

You imported the downloaded customer file. The import check lists 7 missing cities, 18 missing ages, 12 missing spends and 14 missing referral sources (N/A), and no other problems. The Columns table shows 15 distinct cities and 679 distinct customer IDs in 700 rows.

Write two or three sentences for your analysis log: what does the import check not tell you, and what will you check next?

Data: customers_messy · Open in the lab to explore and calculate.

0 words

What you can now do

  • Read a CSV's structure: header, delimiter, quoted values and missing-value tokens
  • Import a CSV into the lab and know what it does to names, spaces, missing tokens and types
  • Verify an import by comparing row, column, missing and distinct counts with expectations
  • Recognise problems an import cannot detect: placeholders, inconsistent spellings and repeated records