Lesson 3 of 16 · Level 1: Beginner
Types of Data and How to Structure a Table
- ⏱ 13 min read
- ❓ 4 review questions
- ✍️ Exercise with solution
- 📥 Downloadable template
In this lesson
- The difference between categorical and numerical data, and why it decides what you can calculate.
- Nominal vs. ordinal, and discrete vs. continuous, with examples from the practice dataset.
- How Excel, SQL and pandas store text, numbers, dates and true/false values.
- The three rules of tidy data, plus wide vs. long tables.
- How to spot (and fix) the table layouts that make analysis painful.
Open the Data Dictionary sheet: it describes all 10 columns of the sales table. Keep it next to you while you classify each column below.
- sales-practice-data.xlsx · sheets Sales Clean and Data Dictionary
Before you calculate anything, you need to know what kind of data each column holds. The type tells you which operations make sense: you can average revenue, but averaging ZIP codes is nonsense. And before you analyze a table, it needs a clean structure: one row per record, one column per variable. This lesson covers both, so every later lesson (formulas, pivots, SQL, pandas) works the first time.
The two big families: categorical and numerical
Almost every column you'll meet belongs to one of two families, with two sub-types each:
Categorical: nominal
Labels with no natural order: region, state, product, channel.
What you can do: count, group, filter, find the most common value. Not average.Categorical: ordinal
Labels with an order: T-shirt sizes (S, M, L), a 1–5 star rating, Bronze/Silver/Gold tiers.
What you can do: count, sort in the right order, use the median. Be careful with averages: the gap between 1 and 2 stars isn't necessarily the same as between 4 and 5.Numerical: discrete
Counts in whole numbers: units in an order, number of support tickets.
What you can do: sum, average, compare. An average can be fractional (4.155 units per order) even if each value is whole.Numerical: continuous
Measurements on a scale: revenue, weight, time on a website.
What you can do: every math operation, plus statistics like standard deviation and percentiles.Two more kinds show up in almost every business table. Dates and times are special: you can sort them, group them by month or quarter, and subtract them (days between order and delivery). Identifiers such as order numbers, ZIP codes or phone numbers look like numbers but aren't quantities. Boston's ZIP code 02108 stored as a number becomes 2108, losing the leading zero. Store identifiers as text.
1. How should you store U.S. ZIP codes in a spreadsheet or database?
ZIP codes are labels, not quantities: adding or averaging them means nothing. Storing them as numbers also drops leading zeros (02108 becomes 2108), which breaks lookups and mailing lists.
Classifying the practice dataset
Here are the 10 columns of the sales table, classified. This is exactly the thinking you should do with any new dataset:
| Column | Type | Example | Useful operations |
|---|---|---|---|
| order_id | Identifier (text) | SO-10001 | Count, check uniqueness |
| order_date | Date | 2025-01-01 | Sort, group by month or quarter |
| region | Categorical, nominal (4 values) | West | Group, filter, count |
| state | Categorical, nominal (17 values) | California | Group, filter, count |
| product | Categorical, nominal (10 sold) | Smart Watch | Group, look up cost |
| category | Categorical, nominal (4 values) | Electronics | Group, filter |
| channel | Categorical, nominal (3 values) | Online | Group, filter |
| units | Numerical, discrete | 2 | Sum, average |
| unit_price | Numerical (currency) | $79 | Average, compare, multiply |
| revenue | Numerical, continuous (currency) | $158 | Sum, average, median, percentiles |
Half of the columns are categories you'll group by, and three are numbers you'll calculate with. That mix is typical of sales data:
The 10 columns of the sales table by type: 1 identifier, 1 date, 5 categorical and 3 numerical.
2. Which of these calculations makes sense on the practice data?
Units is a numerical (discrete) column, so averaging it is meaningful: 831 units ÷ 200 orders = 4.155. Order IDs are identifiers and regions are categories; you can count them, not add or average them.
How tools store data types
Each tool has its own names for data types, but the ideas are the same. Knowing them helps you diagnose the most common beginner bug: a number stored as text, which won't sum, or sorts as "1, 10, 2."
| Kind of data | Excel / Google Sheets | SQL (typical) | pandas |
|---|---|---|---|
| Whole numbers | Number | INTEGER | int64 |
| Decimals and money | Number (currency format) | DECIMAL or REAL | float64 |
| Text | Text | VARCHAR or TEXT | object (str in pandas 3) |
| Dates | Date (a serial number underneath) | DATE or TIMESTAMP | datetime64 |
| True/false | TRUE / FALSE | BOOLEAN | bool |
A detail worth knowing: Excel stores a date as the number of days since its starting point, so January 1, 2025 is really the number 45658 formatted as a date. That's why you can subtract two dates to get the days between them. It's also why a date typed as text (like "10/15/2025" in our raw file) can't be grouped by month until you convert it.
In Excel or Google Sheets, numbers align to the right of the cell by default and text aligns to the left. If a column of prices is left-aligned, or =ISNUMBER(I2) returns FALSE, the values are text. Fix them before you do any math.
Tidy data: the three rules
Statistician Hadley Wickham popularized the term "tidy data" for a structure that makes analysis easy. It comes down to three rules:
- Each variable is a column. Revenue in one column, date in another, never "revenue in Q1" and "revenue in Q2" as separate columns of the same measure.
- Each observation is a row. In our table, one row is one order. That's called the grain of the table.
- Each value is a cell. One product per cell, one number per cell, no "Smart Watch, Yoga Mat" in the same cell.
A tidy table also has a primary key: a column whose value is unique for every row. Here it's order_id. If the same order ID shows up twice, either the grain is different from what you think or there are duplicate rows (our raw file has three; you'll remove them in Lesson 5). The product column also links to the separate Products sheet, where each product appears once with its cost. A column that points to another table's key is called a foreign key, and it's what makes JOINs possible in SQL.
Wide vs. long tables
The same information can be laid out in two shapes. Here's 2025 revenue by quarter for two regions:
- Easy to read
- ●●●●
- Easy to analyze
- ●●●●
- Good for
- Final reports and printed tables.
- Easy to read
- ●●●●
- Easy to analyze
- ●●●●
- Good for
- Pivot tables, SQL, charts, pandas.
Wide format:
| Region | Q1 | Q2 | Q3 | Q4 |
|---|---|---|---|---|
| West | $593 | $14,264 | $6,304 | $15,465 |
| South | $4,109 | $4,927 | $5,505 | $4,143 |
Long format (first four of eight rows):
| Region | Quarter | Revenue |
|---|---|---|
| West | Q1 | $593 |
| West | Q2 | $14,264 |
| West | Q3 | $6,304 |
| West | Q4 | $15,465 |
Wide tables are great for humans; long tables are great for tools. If you add a fifth quarter, the wide table needs a new column and every formula has to change. The long table just gets new rows. The rule of thumb: store and analyze in long format, present in wide format. A pivot table (Lesson 7) is exactly a machine that turns long data into a wide summary.
By the way, look at those numbers: the West sold just $593 in Q1 but $15,465 in Q4, while the South stayed between about $4,100 and $5,500 every quarter. The South is steadier; the West is spikier. You'll find out why in later lessons.
3. Your manager sends a sheet with one row per product and twelve columns named Jan, Feb, …, Dec containing revenue. What shape is it, and what should you do before building a pivot table?
Month is a single variable spread across twelve columns, so the table is wide. Reshaping it to long format (Power Query's "Unpivot" in Excel, or melt in pandas) puts month in one column so you can filter, group and chart it easily.
Table layouts that sabotage analysis
These habits are common in spreadsheets made for printing. Each one breaks sorting, filtering, pivots or imports:
Merged cells in headers or data.
One header row, one name per column, no merges. Use "Center Across Selection" if you need the look.
A "Total" row in the middle or at the bottom of the data.
Keep raw rows only; calculate totals in a separate summary or pivot.
Two values in one cell: "Office Chair x2 (PA)".
Split into product, units and state columns.
Color as data ("orange rows are returns").
Add a column like is_return with TRUE/FALSE. Formulas can't read colors.
Units typed into numbers: "$79", "24 pcs".
Store 79 and 24 as numbers and use number formatting for the $ sign.
Blank rows and columns to "space things out".
Keep the data contiguous; blank rows cut tables in half for filters and pivots.
Document it: the data dictionary
A data dictionary is a short table that explains every column: name, type, meaning, an example and known issues. It takes 15 minutes to write and saves hours of "what does this column mean?" messages. The practice file includes one; for example, it explains that revenue equals units × unit_price before tax and shipping. That single sentence tells you how to recover a missing revenue value, which you'll do in Lesson 5.
4. In the raw practice sheet, order SO-10064 appears on two identical rows. Which tidy-data idea does that violate?
The table's grain is one row per order, so order_id should never repeat. A repeated key means duplicate rows, which would double-count that order's revenue ($700) in any total.
Practice exercise
A colleague pasted these orders into a report. Rebuild them as a tidy table with the columns order_id, state, product, units, unit_price and revenue, and calculate the total revenue.
| Order | Details | Amount |
|---|---|---|
| SO-10001 | Office Chair x2 (PA) @ $249 | $498 |
| SO-10002 | Monitor Stand x24 (NY) @ $45 | $1,080 |
| SO-10003 | Wireless Earbuds x2 (MI) @ $79 | $158 |
| SO-10004 | Smart Watch x1 (IL) @ $199 | $199 |
| TOTAL | $1,935 | |
See solution
| order_id | state | product | units | unit_price | revenue |
|---|---|---|---|---|---|
| SO-10001 | Pennsylvania | Office Chair | 2 | 249 | 498 |
| SO-10002 | New York | Monitor Stand | 24 | 45 | 1080 |
| SO-10003 | Michigan | Wireless Earbuds | 2 | 79 | 158 |
| SO-10004 | Illinois | Smart Watch | 1 | 199 | 199 |
What changed: the "Details" cell held four values (product, units, state, price), so it became four columns. State abbreviations were expanded to match the rest of the dataset. Numbers were stored without "$" or "x". The TOTAL row was removed from the data; you calculate it with =SUM(F2:F5), which gives 498 + 1,080 + 158 + 199 = $1,935. Each revenue also checks out as units × unit_price (for example, 24 × 45 = 1,080).
Summary
- Categorical data (nominal or ordinal) is for grouping and counting; numerical data (discrete or continuous) is for calculating.
- Identifiers like order IDs and ZIP codes look numeric but should be stored as text.
- Excel, SQL and pandas use different type names for the same ideas; a number stored as text is the most common bug.
- Tidy data: each variable a column, each observation a row, each value a cell, with a unique primary key.
- Store and analyze in long format; present in wide format.
- A data dictionary explains every column and its known issues.
Next lesson: Excel and Google Sheets for Data Analysis. You'll answer real questions about the dataset with SUMIFS, COUNTIFS, XLOOKUP and more.
Create your account in 30 seconds, mark your lessons and download your certificate at the end.