Page3/14
DataFrames — Your Data Table · Page 3 of 3
GroupBy & Aggregation
GroupBy & Aggregation
The split-apply-combine pattern is the workhorse of data analysis.
# Split → Apply → Combine
df.groupby("major")["gpa"].mean()
Multiple Aggregations
df.groupby("major").agg({
"gpa": ["mean", "max", "min"],
"projects": "sum"
})
Sorting
df.sort_values("gpa", ascending=False)
df.sort_values(["major", "gpa"], ascending=[True, False])
Value Counts
df["major"].value_counts() # frequency of each major
Real-world use: This is equivalent to SQL's
GROUP BY ... HAVING— you'll use it in every data analysis project.
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…