How to compute the average of a dataframe column

1 min

Here is the simplest formula to compute the average of a list of variables.

The arithmetic mean formula

The pandas library has a simple method to compute the mean of a list.

The .mean() method, here is an example:

import pandas as pd

# We read a sample dataset from the web.
df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')

# We select the sepal length column and apply the mean  method
print(df["sepal_length"].mean())
We print the column average

Here you are ! You now know how to compute the average of a dataframe column.