# Aggregates in Pandas

Learn the basics of aggregate functions in Pandas, which let us calculate quantities that describe groups of data..

Start## Key Concepts

Review core concepts you need to learn to master this subject

Pandasâ€™ Groupby

Pandasâ€™ Groupby

```
df = pd.DataFrame([
["Amy","Assignment 1",75],
["Amy","Assignment 2",35],
["Bob","Assignment 1",99],
["Bob","Assignment 2",35]
], columns=["Name", "Assignment", "Grade"])
df.groupby('Name').Grade.mean()
# output of the groupby command
|Name | Grade|
| - | - |
|Amy | 55|
|Bob | 67|
```

In a pandas `DataFrame`

, aggregate statistic functions can be applied across multiple rows by using a `groupby`

function. In the example, the code takes all of the elements that are the same in `Name`

and groups them, replacing the values in `Grade`

with their mean. Instead of `mean()`

any aggregate statistics function, like `median()`

or `max()`

, can be used. Note that to use the `groupby()`

function, at least two columns must be supplied.

Aggregates in Pandas

Lesson 1 of 1

- 1This lesson you will learn about
*aggregates*in Pandas. An*aggregate*statistic is a way of creating a single number that describes a group of numbers. Common aggregate statistics include mean,â€¦ - 2Aggregate functions summarize many data points (i.e., a column of a dataframe) into a smaller set of values. Some examples of this type of calculation include: * The DataFrame customers contains â€¦
- 3When we have a bunch of data, we often want to calculate aggregate statistics (mean, standard deviation, median, percentiles, etc.) over certain subsets of the data. Suppose we have a grade book wâ€¦
- 4After using groupby, we often need to clean our resulting data. As we saw in the previous exercise, the groupby function creates a new Series, not a DataFrame. For our ShoeFly.com example, the inâ€¦
- 5Sometimes, the operation that you want to perform is more complicated than mean or count. In those cases, you can use the apply method and lambda functions, just like we did for individual column â€¦
- 6Sometimes, we want to group by more than one column. We can easily do this by passing a list of column names into the groupby method. Imagine that we run a chain of stores and have data about theâ€¦
- 7When we perform a groupby across multiple columns, we often want to change how our data is stored. For instance, recall the example where we are running a chain of stores and have data about the nâ€¦

## What you'll create

Portfolio projects that showcase your new skills

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory