Blog/Pivot & Reshape

Preprocessing

Pivot & Reshape

Long vs wide data, and when to switch

SK

Skari Team

Skari

July 2026·7 min read

Pivot / Reshape

Long data (one row per observation) reshapes into wide (one row per entity, columns per category).

longwide

The same facts can be stored two ways. Long data has one row per observation — customer, month, value. Wide data has one row per entity, with a column for each category — customer, then one column per month. The diagram above shows the reshape between them.

Note

Neither shape is more correct. The right one depends on what you're about to do — modeling, charting, or joining each prefer a different layout.

Which Shape for Which Task

TaskPreferred shape
Most modeling / tidy analysisLong — one observation per row
Cross-tab reports and dashboardsWide — categories as columns
Time-series per entityOften wide — one column per period

Pivoting long → wide spreads a category column into many columns; going wide → long collapses them back into key-value pairs.

Pivot vs Aggregate

A pivot often carries an aggregation: if several rows share the same entity and category, you must decide how to combine them — sum, mean, count. Choosing the wrong aggregation quietly changes what each cell means.

Watch out

When a pivot has multiple values per cell, the aggregation is a decision, not a detail. Confirm you want a sum vs a mean before you reshape.

The Reshape Traps

  • Silent aggregation hiding duplicate keys you didn't know about
  • Wide data with sparse categories creating lots of missing cells
  • Losing a column you needed because it wasn't part of the pivot

Pivoting in the SKARI Data Editor

The Data Editor's pivot tool reshapes data without code: choose the row key, the column to spread, the value, and the aggregation — then preview the reshaped table before committing.

  • Long-to-wide pivot with an explicit aggregation choice
  • A preview of the reshaped table before you apply it
  • The reshape recorded as a tracked pipeline step

Takeaway

You pick the aggregation on purpose and see the result first — no silent surprises buried in a reshape.

Frequently Asked Questions

Long or wide for modeling?

Usually long ('tidy') data — one observation per row is what most modeling and plotting tools expect.

What's melt / unpivot?

The reverse of a pivot: it collapses wide columns back into long key-value rows.

Why did my pivot create blanks?

Because some entity-category combinations had no data — sparse categories leave empty cells in wide form.

Conclusion

Pivoting is just choosing the layout that fits the next step. Know when you need long vs wide, decide the aggregation deliberately, and preview the result — and reshaping becomes a tool, not a source of silent errors.

Takeaway

Reshape to fit the task, not by habit — and always confirm the aggregation before the pivot rewrites your cells.

Joining Datasets

Combining tables after reshaping

Feature Engineering

Building features from wide layouts

Column Profiling

Checking the reshaped result