Skip to content
wannacode

The first table

In short: pd.read_csv loads a CSV file into a table (a DataFrame), and head, shape, info and describe show the rows, the size, the types and the summaries before you compute anything.

Problem

“How many orders do we have?”

The manager sends you orders.csv and asks how many orders there are and what the average is. The temptation is to open the file, write mean() and send back a number.

But you do not know yet what is in the file. Is a row an order, or a line of an order? Are there empty cells? Are the numbers numbers, or text like “1,60 €”? A mean of the wrong column gives a wrong answer that looks perfectly serious.

So analysis starts with a first look: what is in the table, before you compute with it.

The idea

The table: read_csv

CSV is a text file with a table: the first line holds the column names, and every next line is one record, with the values separated by commas. Almost every system gives you one: the shop, the bank, Excel.

pandas is the Python library for tables. pd.read_csv reads the file and returns a DataFrame: a table with column names and a number for every row on the left (that is the index). head() shows the first five rows:

Pythondata: the shop tables

import pandas as pd is everyone’s habit: pandas is written pd. The file orders.csv sits next to the code, together with the other shop tables: products.csv, customers.csv, order_items.csv, categories.csv and reviews.csv.

The last line has no print, and still the table comes out. That is how a notebook (Jupyter), where analysts write, works: the value of the last line is shown by itself.

The idea

How many and what: shape and info

shape is a pair (rows, columns). info() describes every column: how many values it has and of what type:

Pythondata: the shop tables

Read it top to bottom:

  • 25 rows, 6 columns. No column is completely empty.
  • category_id has 24 values out of 25: one product has no category.
  • The types: int64 is whole numbers, float64 decimals, str text. The date added_at is text: pandas does not recognise a date by itself. We will get to that.
1. The category_id column holds whole numbers (3, 4, 5…). Why does pandas read it as float64?
More precisely, if you are curious

The str type is new in pandas 3 (2026). In older versions and in many articles text is object. The meaning is the same: the column holds strings.

The idea

The numbers in short: describe

describe() summarises a numeric column: how many values, the mean (mean), the spread (std), the smallest, the largest and the three quarters (25%, 50%, 75%):

Pythondata: the shop tables

The mean price is €7.04, and 50% (the median, the price in the middle) is €2.80. That is a big gap: a few expensive products (the knives at €39, the pan at €24.90) pull the mean up. Tell the manager that “our product costs €7 on average” and they will picture a different shop.

Whether to use the mean or the median is for the statistics module. For now the rule is: look at both.

See it

Which product has no category

info() said one category is missing. Here is the product:

Pythondata: the shop tables

The gift card is not food and not for the home. The gap is real information, not a mistake in the file. Its stock is 999: a placeholder that means “no limit”. Add up the stock in the warehouse and it will skew the result.

That is what the first look gives you: before the first sum you know what is not what it seems.

Try it

The order lines

How many rows does order_items.csv have, and how many units of a product are on a line on average? Put them in rows and avg_qty.

Pythondata: the shop tables

Exercise

The newest orders

head() has a sibling: tail() shows the last rows. Both take how many rows you want: head(10).

The orders file is sorted by date. Put the last 4 orders in latest.

Pythondata: the shop tables
More precisely, if you are curious

A file exported from Excel in many European languages uses semicolons between values and a comma in numbers: 1,60. Then it is pd.read_csv('file.csv', sep=';', decimal=','). Text from old programs is sometimes in a regional encoding such as Windows-1251: encoding='cp1251'. An Excel sheet is read directly with pd.read_excel, and a database table with pd.read_sql (see the Databases and SQL course).

Test

Check yourself

1. What does orders.shape return for a table with 60 rows and 4 columns?
2. The mean product price is €7.04 and the median is €2.80. What does that tell you?
3. Which method tells you how many values are missing in each column and what type it is?
4. The last line of the code is orders.head(), with no print. What do you see?

Made by Ivo Gergov as part of Evo Tech's campaign for accessible programming education ·