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
  1. The two big families: categorical and numerical
  2. Classifying the practice dataset
  3. How tools store data types
  4. Tidy data: the three rules
  5. Wide vs. long tables
  6. Table layouts that sabotage analysis
  7. Document it: the data dictionary
  8. Summary
What you'll learn
  • 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.
📥 Practice this lesson

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.

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?

  • As whole numbers, because they contain only digits
  • As text, because they're identifiers and some start with zero
  • As decimals, so they sort correctly

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:

ColumnTypeExampleUseful operations
order_idIdentifier (text)SO-10001Count, check uniqueness
order_dateDate2025-01-01Sort, group by month or quarter
regionCategorical, nominal (4 values)WestGroup, filter, count
stateCategorical, nominal (17 values)CaliforniaGroup, filter, count
productCategorical, nominal (10 sold)Smart WatchGroup, look up cost
categoryCategorical, nominal (4 values)ElectronicsGroup, filter
channelCategorical, nominal (3 values)OnlineGroup, filter
unitsNumerical, discrete2Sum, average
unit_priceNumerical (currency)$79Average, compare, multiply
revenueNumerical, continuous (currency)$158Sum, 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?

  • The average of order_id
  • The sum of the region column
  • The average units per order, which is 4.155

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 dataExcel / Google SheetsSQL (typical)pandas
Whole numbersNumberINTEGERint64
Decimals and moneyNumber (currency format)DECIMAL or REALfloat64
TextTextVARCHAR or TEXTobject (str in pandas 3)
DatesDate (a serial number underneath)DATE or TIMESTAMPdatetime64
True/falseTRUE / FALSEBOOLEANbool

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.

Quick test for numbers stored as text

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:

  1. 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.
  2. Each observation is a row. In our table, one row is one order. That's called the grain of the table.
  3. 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:

WideOne column per quarter
Easy to read
●●●●
Easy to analyze
●●●●
Good for
Final reports and printed tables.
For people
LongOne row per region and quarter
Easy to read
●●●●
Easy to analyze
●●●●
Good for
Pivot tables, SQL, charts, pandas.
For tools

Wide format:

RegionQ1Q2Q3Q4
West$593$14,264$6,304$15,465
South$4,109$4,927$5,505$4,143

Long format (first four of eight rows):

RegionQuarterRevenue
WestQ1$593
WestQ2$14,264
WestQ3$6,304
WestQ4$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?

  • Wide; reshape it to long (product, month, revenue) so month becomes one column
  • Long; nothing, it's ready
  • Wide; delete the months you don't need

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?

  • Each variable is a column
  • Each value is a cell
  • The primary key (order_id) should be unique, because the grain is one row per order

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.

OrderDetailsAmount
SO-10001Office Chair x2 (PA) @ $249$498
SO-10002Monitor Stand x24 (NY) @ $45$1,080
SO-10003Wireless Earbuds x2 (MI) @ $79$158
SO-10004Smart Watch x1 (IL) @ $199$199
TOTAL$1,935
See solution
order_idstateproductunitsunit_pricerevenue
SO-10001PennsylvaniaOffice Chair2249498
SO-10002New YorkMonitor Stand24451080
SO-10003MichiganWireless Earbuds279158
SO-10004IllinoisSmart Watch1199199

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.

🎓 Save your progress and get a free certificate

Create your account in 30 seconds, mark your lessons and download your certificate at the end.

Enroll for free