Long Format

noun

say it: “LAWNG FOR-mat” /ˈlɔŋ ˈfɔrmæt/

A way of laying out a table with one row for each value, and one column for each kind of information, such as student, quiz and score.

What is long format for a table?

A table in long format has one row for each value and one column for each kind of value, such as student, quiz and score. It's longer to read, but simple to filter, group and chart; pivot() turns it back into wide format.

import pandas as pd
long = pd.DataFrame({"student_id": [101, 101, 102], "quiz": ["quiz1", "quiz2", "quiz1"], "score": [88, 90, 92]})
print(long.groupby("quiz")["score"].mean())
# quiz
# quiz1    90.0
# quiz2    90.0

In a sentence

  • “Grouping by quiz is one line once the scores are in long format.”
  • “In long format, each quiz score has its own row.”

Level: Apprentice · More Python terms at this level

Updated