Tsallaka zuwa abun ciki
Justice Tech School

groupby

groupby splits rows into groups, applies a function and combines the result.

Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df.groupby("country")["score"].mean())
print(df.groupby("country").size())

Result

country
GH    78.000000
NG    82.666667
Name: score, dtype: float64
country
GH    1
NG    3
dtype: int64

Exercise

Group rows.

df.("country")

Quiz Test

What does size() count?

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