Key Concepts

Review core concepts you need to learn to master this subject

Pandas DataFrame Aggregate Function

df.columnName.mean() # Average of all values in column df.columnName.std() # Standard deviation of column df.columnName.median() # Median value of column df.columnName.max() # Maximum value in column df.columnName.min() # Minimum value in column df.columnName.count() # Number of values in column df.columnName.nunique() # Number of unique values in column df.columnName.unique() # List of unique values in column

Pandas’ aggregate statistics functions can be used to calculate statistics on a column of a DataFrame. For example, df.columnName.mean() computes the mean of the column columnName of dataframe df. The code block shows how to calculate statistics on the column columnName of df using Pandas’ aggregate statistics functions.

Aggregates in Pandas
Lesson 1 of 1
  1. 1
    This 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,…
  2. 2
    Aggregate 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 …
  3. 3
    When 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…
  4. 4
    After 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 example, the in…
  5. 5
    Sometimes, 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 …
  6. 6
    Sometimes, 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…
  7. 7
    When 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…
  8. 8
    This lesson introduced you to aggregates in Pandas. You learned: * How to perform aggregate statistics over individual rows with the same value using groupby. * How to rearrange a DataFrame into…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

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

Pro Logo