← Pandas
Lesson 3 of 5
GroupBy and aggregation
Watch, read the card, then practise. groupby basics · Several summaries at once · Counting values
The video for this lesson is being recorded.
Meanwhile, the notes below and the 60-second cards cover the same ideas.
Practise this topicgroupby basics
groupby splits the table into groups and summarises each one.
Remember: Split, apply, combine.
Several summaries at once
agg lets you work out several summaries at once.
Remember: One groupby, many summaries with agg.
Counting values
value_counts counts how often each value appears in a column.
Remember: Quickest way to see what's in a column.
Try the example in Code Lab
import pandas as pd
df = pd.DataFrame({"city": ["Pune", "Delhi", "Pune"], "marks": [82, 67, 91]})
print(df.groupby("city")["marks"].mean().to_dict())