Skip to content
Statistics

What is the difference between "long" and "wide" format data?

Wide: categorical data is grouped in a single row, long: each row is an observation belonging to a particular category.

datasciencetrivia.com

Card 1 of 259. Answer: Wide: categorical data is grouped in a single row, long: each row is an observation belonging to a particular category.

Created by santiviquez

About · Quizzes · History of AI · To suggest new questions or report an error send me a dm.

The longer answer

In wide format each subject has one row and repeated measurements spread across columns, such as one row per student with columns math, physics and chemistry. In long format each row is a single observation, so the same student appears three times with a subject column and a score column.

Long format is what most plotting and modelling tools expect, because every variable is one column; it matches the "tidy data" convention. Wide format is easier for people to read and is what many spreadsheets and some algorithms, like a feature matrix for scikit-learn, need.

Converting between them is called melting or pivoting. In pandas, melt goes from wide to long and pivot or pivot_table goes from long to wide; in R the tidyr functions pivot_longer and pivot_wider do the same.

All questions