Skip to content
Start free

What is one row of this table?

Look at eight orders and say, in one sentence, what a single row stands for before you trust any count of them.

3 parts · 3, 4 and 2 min

Free course. Your Maestro, an AI, .

Suppose a small shop asks an AI assistant, "How many customers have at least one paid order?" The AI answers 6 and shows the few lines of code it ran on the shop's table.

Before you read that code, you need one fact about the table itself: what a single row stands for. Analysts call this the of the table. Whenever a program counts rows, it counts whatever one row represents. If each row is one customer, a row count gives you customers. If each row is one order, a row count gives you orders, even when your question asked about customers.

The table the AI used has 8 rows and four columns: order_id, customer_id, status, and amount. Because both order_id and customer_id end in "id", it is easy to assume that every row holds a different customer. A column name with "id" in it only means the column holds an identifier, and that identifier can still appear on more than one row.

Two ways to find what one row stands for

You can check what one row represents by comparing individual rows in the table or by comparing two counts in .

1. The two-rows test. Find two rows that share the same value in the column you care about, and see what changes between them. In this table, customer "C01" appears on two rows: one has order_id "P01" and the other has order_id "P02". Customer "C03" also appears on two rows, with order_id "P04" and order_id "P06". Because the same customer shows up on multiple rows with a different order_id each time, one row represents one order. A single customer can place several orders and appear on several rows.

Filtering the table leaves the meaning of a row unchanged. If you filter the table to keep only the "paid" rows and hide the "cancelled" ones, fewer rows remain on screen, yet each remaining row still stands for one order.

2. Comparing the row count with the distinct count. When a table has hundreds of rows, scanning by eye takes too long. Instead, you can compare the total number of rows with the number of distinct (unique) values in each identifier column. The exercise below runs three lines of code on the table, which is loaded under the name data:

  • print(data) displays all 8 rows so you can inspect the table directly.
  • len(data) counts the total number of rows in data.
  • data["order_id"].nunique() looks inside the order_id column and counts how many distinct values appear there, counting each value once even if it repeats.

When a column's .nunique() count matches len(data), every row has a different value in that column. When .nunique() is smaller than len(data), some values in that column repeat across rows. If the syntax in data["order_id"].nunique() looks unfamiliar, ask your Maestro to break down each part.

Try it

Run the code below to print the table, the row count, and the count of distinct order_id values. Then add one line at the bottom that prints how many distinct customer_id values there are. You can copy the order_id line and change "order_id" to "customer_id" in both places so your new line reads print("Distinct customer_id values:", data["customer_id"].nunique()). If your new line gives an error or you are unsure what to edit, ask your Maestro for a hint.

A good place to stop. Up next: the exercise · 4 min

Your turn

Run the code and read the table. Then add a line that prints how many distinct customer_id values there are. You're done when you can finish the sentence "One row is one ___" and name a customer who appears on two rows.

Data: shop-orders, 8 rows
The exercise's data, "shop-orders". Your edits run with your code.
RowRemove
1
2
3
4
5
6
7
8

A good place to stop. Up next: part 3 of 3 · 2 min

Check your result

When your added line runs, the output at the bottom shows three counts:

  • "Rows: 8"
  • "Distinct order_id values: 8"
  • "Distinct customer_id values: 6"

Because the 8 distinct order_id values match the 8 rows, every row in data is a separate order ("P01" through "P08"). By contrast, those 8 orders belong to only 6 distinct customers ("C01" through "C06"), because "C01" and "C03" each placed two orders.

To finish the exercise, write one sentence that completes "One row of this table is one ___" and explains how you know a customer can appear on more than one row, naming at least one customer who repeats. Once you have your sentence, send it to your Maestro to check that it covers both the row and the repeating customers.

Check yourself: In the shop-orders table, 8 rows have 8 distinct order_id values and 6 distinct customer_id values. Which statement accurately describes what one row of this table represents?