BeginnerLesson 2 of 305 min read

Tables, Columns and Data Types: Look Before You Analyse

Learn to read a table, tell the five kinds of value apart, and check size and types before you calculate anything.

In this lesson you will

  • Read a CSV file and a table
  • Explain what a row and a column are
  • Tell the main kinds of value apart
  • Check size and types before analysing

About 24 minutes

A table is just a list of things

Omar, one of Leila’s volunteers, has kept a record of every repair in a spreadsheet and exported it as a file called visits.csv. A CSV file is plain text: one row per line, with the values separated by commas. Here are its first lines.

visit_id,date,customer,bike,repair,minutes,cost,rating,source
1,2026-09-05,Eli Moss,road,wheel,47,23.5,5,online
2,2026-09-08,Ben Cole,kids,chain,28,9.0,3,poster
3,2026-09-05,Gus Hart,mountain,gears,37,21.0,,passing
4,2026-09-08,Gus Hart, Road,brakes,32,17.0,2,passing
5,2026-09-05,Gus Hart,kids,gears,43,18.0,2,poster
6,2026-09-15,  ben cole,hybrid,gears,44,21.0,5,poster
6,2026-09-15,  ben cole,hybrid,gears,44,21.0,5,poster
7,2026-09-12,Ben Cole,kids,gears,39,19.5,2,poster

Before you calculate anything, learn to read a table. Each row describes one thing: here, one visit to the workshop. Each column holds one kind of fact about every row: the date, the customer, the bike, and so on. This shape, one thing per row and one fact per column, is called tidy data, and almost every analysis tool expects it. If a table has two visits squeezed into one row, or a column that mixes a number and a note, you will fight the tool at every step.

Five kinds of value

Kind Examples in this file
Whole numbers minutes, visit_id
Decimal numbers cost, rating
Dates date
Categories (a few repeating labels) bike, repair, source
Free text (names, notes) customer

The kind decides what you are allowed to do. You can add up minutes, but adding up bike types is meaningless. You can sort dates and measure the gap between them. You can count categories. Watch out for identifiers: a visit number is a number, but averaging visit numbers means nothing. It is a label that happens to use digits.

Look before you leap

The first job in any analysis is simply to look. The program below reads the file with the pandas library and prints the size of the table, the type of each column, and the first three rows. It prints each row on one short line so that it fits a phone screen.

import pandas as pd
df = pd.read_csv("visits.csv")
print("rows:", len(df))
print("columns:", len(df.columns))
for name in df.columns:
    print(name + ":", df[name].dtype)
for row in df.head(3).itertuples():
    print(row.visit_id, row.date, row.bike, row.repair)
rows: 40
columns: 9
visit_id: int64
date: str
customer: str
bike: str
repair: str
minutes: int64
cost: str
rating: float64
source: str
1 2026-09-05 road wheel
2 2026-09-08 kids chain
3 2026-09-05 mountain gears

The file has 40 rows and 9 columns. Now read the types carefully, because they hide two small surprises. The cost column is listed as text, although cost is obviously a number. Something in that column is not a number, and the next lesson finds it. The rating column is listed as decimal numbers, although ratings are whole numbers from one to five. When a column of whole numbers has gaps, the pandas library cannot store the gaps in whole numbers, so it quietly switches to decimals. That tells us that some ratings are missing. Neither problem was visible in the first three rows.

The names printed for the types, such as str or int64, depend on the version of the library. An older version prints object for text. The idea is the same: check that every column has the kind of value you expect.

Good habits with files and names

  • Keep the original. Never edit the raw file. Make a cleaned copy, so that you can always start again and show what you changed.
  • Decide what one row means. Is a row a visit, a customer or a day? Mixing them makes counts wrong, because a customer who visits three times would be counted three times.
  • Use plain column names. Short, lower case, no spaces, such as minutes or repair. They are easier to type and less likely to cause errors in code.
  • Read the header line. The first line holds the column names and is not data. Tools can mistake it for a row if the file is read the wrong way.
Common mistake: judging a file by its first rows

Trusting the first few rows. Problems hide further down the file. Always check the size, the types and the counts, not just the top.

A deliberately messy file

All the visits are made up, and the money is sample money. The file was created for this course and contains deliberate mistakes that the next lessons will find and fix. Type names depend on your version of pandas.

Open a table you already have, in a spreadsheet or a file. For each column, write down its kind, and note one value that does not fit.

Practice for this lesson

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

In tidy data, what does each row hold?

  1. One kind of fact about everything
  2. One thing, such as one visit
  3. A whole month of data
  4. A chart

Each row in the file was one visit.

What does each column hold?

  1. One whole record
  2. The title of the file
  3. One kind of fact about every row
  4. The cleaning notes

The columns were date, customer, bike, repair, and so on.

Why is the visit number not something to average?

  1. It is an identifier, a label that happens to use digits
  2. It is too large
  3. It is text
  4. It is a date

Averaging labels means nothing.

Why was the cost column listed as text?

  1. Cost is always text
  2. The file was empty
  3. At least one value in it is not a number
  4. The column was a date

The next lesson finds the value that is not a number.

What does a whole-number column turning into decimals suggest?

  1. Some values are missing
  2. The numbers are too large
  3. The column is a date
  4. The file is compressed

The rating column showed this sign of missing ratings.

Summary

  • One thing per row and one fact per column is tidy data.
  • The kind of a column decides what you can do with it.
  • Identifiers are labels, not numbers to calculate with.
  • Check size and types first; types can reveal hidden problems.

Next lesson

Lesson 3 starts cleaning: duplicates, missing values and wrong types.

Questions

What is a CSV file?

A plain text file where each line is a row and the values are separated by commas. Almost every tool can read and write it, which is why it is the common way to move tables around.

Can I do all this in a spreadsheet?

Yes. Rows and columns work the same way, and you can check types by looking at how the cells align or by using the type checking functions. The pandas library makes each step repeatable.

Why do the type names differ from my screen?

They depend on the version of the library. An older version shows object for text. Focus on whether each column holds the kind of value you expect.

Progress is saved in this browser.