Mean Function in Python pandas (Dataframe, Row and column wise mean)

mean() – Mean Function in python pandas is used to calculate the arithmetic mean of a given set of numbers, mean of a data frame ,mean of column and mean of rows , lets see an example of each . We need to use the package name “statistics” in calculation of mean. In this tutorial we will learn,

  • How to find the mean of a given set of numbers
  • How to find mean of a dataframe
  • How to find the mean of a column in dataframe
  • How to find row mean of a dataframe

Mean Function in Python

Simple mean function is shown below

# calculate arithmetic mean
Import statistics





Mean of a dataframe:

Create dataframe

import pandas as pd
import numpy as np

#Create a DataFrame
d = {

df = pd.DataFrame(d)

So the resultant dataframe will be

mean function in python pandas

Mean of the dataframe:

# mean of the dataframe

it will calculate the mean of the dataframe across columns so the output will be

Score1  58.0
Score2  73.0
dtype:  float64


Column Mean of the dataframe:

# column mean of the dataframe

axis=0 argument calculates the column wise mean of the dataframe so the result will be

Score1 58.0
Score2 73.0
dtype: float64


Row Mean of the dataframe:

# Row mean of the dataframe

axis=1 argument calculates the row wise mean of the dataframe so the result will be

0   75.5
1   67.0
2   61.0
3   64.5
4   39.0
5   74.5
6   80.5
7   71.0
8   43.0
9   62.0
10   85.0
11   63.0
dtype: float64


Calculate the mean of the specific Column

# mean of the specific column

the above code calculates the mean of the “Score1” column so the result will be



previous-small mean function in python                                                                                                           next_small mean function in python