Dataset Reshaping: Choosing What One Row Represents

Dataset reshaping reorganizes the same observations into a different arrangement of rows and columns. You encounter it when a spreadsheet report stores months across columns but an analytical task needs a month column, or when a presentation needs categories displayed side by side. The central decision is what one row should represent. A successful reshape changes the layout while preserving the meaning of the data.

Start with the observation and its key

Before changing a table, finish the sentence: “Each row represents one …”. In a monthly retail dataset, that might be one store in one month. In a product report, it might be one product at one branch on one date.


An observation key is a column, or combination of columns, that uniquely identifies an observation at the intended level of detail. Store alone does not identify a monthly observation when each store appears in several months. Store together with month may do so, provided the dataset covers only one year. With multiple years, you also need year or a complete date.


Separate identifiers from measurements. Identifiers describe which observation a value belongs to; measurements record quantities such as revenue or inventory. A column heading such as sales_March contains both a measurement name and a category label that you may need to separate.

Move from wide to long

In a wide layout, repeated categories such as months occupy separate columns. In a long layout, those category labels appear as values in a column, with the corresponding measurements in another column.


Layout

What one row represents

Typical columns

Wide

One store, with several months across columns

Store, February sales, March sales

Long

One store in one month

Store, month, sales


A wide sales table becomes a long table with separate store, month, and sales columns.


To reshape wide data into long data, keep the identifier columns, select the repeated measurement columns, and create columns for their category labels and values. In the diagram, each store identifier repeats because its February and March measurements become separate rows. The sales amounts do not change.


Long data often suits comparisons across time because month is an explicit variable. Wide data can suit a report that places months beside one another. Neither layout is automatically best for every task.



Move from long to wide

To reshape long data into wide data, choose the columns that identify output rows, the category column that supplies new headings, and the measurement column that supplies cell values.


Each output cell needs an unambiguous source value. If two records share the same output-row identifiers and category, investigate why. They might be duplicate records, or they might differ by an omitted identifier such as sales channel.



When you have several measurement types, preserve their identities. Monthly unit sales and monthly prices can become separate unit-sales and price columns alongside a month column. Mixing them into one unlabeled value column loses their meaning and units.

Check that meaning survived

Validate the result against the intended key, expected categories, original values, and missing entries. A changed row count can be correct: the diagram expands two store rows into four store-month rows. The relevant question is whether each expected observation appears correctly.


Keep missing values distinct from zero. Zero is a recorded quantity; missing means the quantity is unavailable. Also distinguish a missing measurement in an existing record from a category combination that had no source record. Preserve a presence indicator if you need that distinction for reconstruction.


A reshape is reversible when the identifiers, category labels, measurement identities, values, and necessary missingness information survive without aggregation. Returning to the original layout is a useful check, alongside checking keys and values.


What to remember

  • Define what one row represents and identify its key.
  • Move category labels between headings and values deliberately.
  • Resolve ambiguous cells before widening.
  • Preserve measurement types, units, zeros, and missingness.

Example: Reshaping a Café Revenue Report

A finance analyst receives the following report for April and May 2026. Revenue is measured in CAD. Each café has an expected observation for both months; missing means the revenue has not yet been reported.


Café ID

April revenue

May revenue

C17

18400

19750

C24

16200

missing


The analyst needs a table with one row per café and month for monthly reporting.


a) Identify the required row meaning, observation key, and output columns.


One output row must represent one café in one month. Café ID identifies the café but cannot identify a monthly observation by itself, because each café appears in both months.


Use Café ID together with Month as the observation key. Store the month as April 2026 or May 2026 so the year remains explicit. Keep revenue as a measurement with its unit, CAD.


The output columns are Café ID, Month, and Revenue in CAD. Within this report, each Café ID-Month combination should occur once.


b) Construct the long table, preserving all expected observations.


Keep Café ID as an identifier. Move April and May from the revenue headings into Month, including the stated year. Place each corresponding amount in Revenue in CAD.


For C17, April contributes CAD ________ and May contributes CAD ________. For C24, April contributes CAD ________ and May contributes a missing value. Keep the missing observation because May is explicitly expected for C24.


Using the column order Café ID, Month, and Revenue in CAD, the long table has these rows:

  • C17; April 2026; 18400.
  • C17; May 2026; 19750.
  • C24; April 2026; 16200.
  • C24; May 2026; missing.

Two cafés with two expected months each produce four rows. No revenue values were added together, and missing was not replaced with zero.


c) Reconstruct the wide report and explain how to check that the reshape preserved its information.


Use Café ID to identify output rows, Month to supply the new headings, and Revenue in CAD to supply cell values. Each Café ID-Month pair occurs once, so every output cell has one unambiguous source value.


Using the column order Café ID, April 2026 revenue in CAD, and May 2026 revenue in CAD, the reconstructed wide report has these rows:

  • C17; 18400; 19750.
  • C24; 16200; missing.

Compare the reconstructed entries with the source. C17 retains CAD 18400 for April and CAD 19750 for May. C24 retains CAD 16200 for April and a missing May measurement. The headings now state the year and unit explicitly, while preserving their original meaning.


Also check that both café identifiers remain, that April and May are both represented, and that each café-month key is unique in the long table. The reconstructed table has two café rows and two monthly measurement columns. These checks confirm that the reshape changed the arrangement while preserving every expected observation, value, and missing entry.

A retailer has columns Region, January returns, February returns, and March returns. Each returns column records a count of returned items. An analyst needs one row for each region in each month. Which output structure meets that requirement?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A retailer keeps one inventory record per product per warehouse. Its reorder table also has one record per product per warehouse. Product IDs repeat across warehouses, and warehouse IDs repeat across products. To match the corresponding records, the retailer uses product ID and warehouse ID together. What two-word term describes this combination of fields used to identify each record?

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

A purchasing report has one row per product and these columns:


Column

Meaning

Product

Product identifier

June demand

Demand in units during June

July demand

Demand in units during July

June price

Price in CAD per unit during June

July price

Price in CAD per unit during July


The analyst wants one row per product and month, with demand and price available as separate measurements. Which design preserves the required information?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Extra Practice