Skip to content
Justice Tech School

pivot_table

pivot_table summarises data in a grid with rows, columns and a function.

Example
df = pd.DataFrame({"c": ["NG", "NG", "GH", "GH"], "lvl": ["A", "B", "A", "B"], "s": [90, 80, 70, 60]})
print(df.pivot_table(index="c", columns="lvl", values="s", aggfunc="mean"))

Result

lvl     A     B
c              
GH   70.0  60.0
NG   90.0  80.0

Exercise

Grid summary.

df.(index="c")

Quiz Test

What does aggfunc set?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.