# How to calculate the average of one or more columns in a Pandas DataFrame?

In order to find the average of a single or multiple pandas columns we use the DataFrame mean() function. Here are two simple examples, that assume your DataFrame name is mydf and you columns are col_1 and col_2:

``````# one column
mydf['col_1'].mean()

# multiple
mydf[['col_1', 'col_2']].mean()``````

## Compute average of selected pandas columns – Example

Let’s get started by prepping our test DataFrame. As usual, we’ll use the auto-generated candidates data.

Here we go:

``````import pandas as pd

print(data)``````

Here’s the result.

Note that if you want to follow along this example, you can copy the following table and use the pd.read_clipboard() method to populate your own dataframe.

``````import pandas as pd

### Find the mean / average of one column

To find the average of one column (Series), we simply type:

``data['salary'].mean()``

The result will be 126.

### Calculate mean of multiple columns

In our case, we can simply invoke the mean() method on the DataFrame itself.

``data['salary'].mean()``

The result will be:

``````salary            126.0
num_candidates     80.5
dtype: float64``````

Chances are that your DataFrame will be wider, and contains several columns. In that case, we’ll first subset our DataFrame by the relevant columns and then calculate the mean.

``````cols = ['salary', 'num_candidates']

data[cols].mean()``````

The result will be similar.

### Find pandas columns average with describe()

We typically use the describe() DataFrame method in order to quickly look into our dataset descriptive statistical figures – such as the cont, minimum and maximum values, standard deviation etc’.

We can use the following snippet to get a Series representing the mean of each numeric column in our DataFrame:

``````stats = data.describe()
stats.loc['mean']
``````

This will return the following Series:

```salary            126.0
num_candidates     80.5
Name: mean, dtype: float64```

### Creating a DataFrame or list from your columns mean values

You can easily turn your mean values into a new DataFrame or to a list:

``````data_mean = pd.DataFrame(data.mean(), columns=['mean_values'])

#create list of mean values
mean_lst = data.mean().to_list``````

### Plot column average in Pandas

As the Pandas library contains basic methods for plotting, making a simple chart to visualize multiple column averages is a breeze:

``data.mean().plot(kind='bar');``

Here’s the chart:

### Calculate the mean of you Series with df.describe()

We can use the DataFrame method pd.describe to quickly look into the key statistical calculations of our DataFrame numeric columns – including the mean.

``data.describe().round()``

And the result:

### Calculate the median of a DataFrame

For completeness, here’s a simple snippet to calculate the median of multiple DataFrame columns:

``````data.median()
``````

This will render the following results, which represent the median observation of each columns of the dataset.

```salary            122.0
num_candidates     79.5
dtype: float64```