Several Aggregations
agg runs several functions at once. Named aggregation gives clean column names.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
r = df.groupby("country").agg(n=("name", "count"), avg=("score", "mean"), best=("score", "max"))
print(r)Result
n avg best country GH 1 78.000000 78 NG 3 82.666667 92
Exercise
Many functions.
.(["min", "max"])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.