4. Grouping and Aggregating Data. In Pandas, you can group rows of a DataFrame by one or more columns and perform aggregate operations on the groups. You can use the groupby()
function and aggregation functions like sum()
, mean()
, and count()
.
For example, you can group students by age and calculate the average age of each group like this: df.groupby('Age')['Age'].mean()
.