Pandas DataFrame.mean()

The mean() function is used to return the mean of the values for the requested axis. If we apply this method on a Series object, then it returns a scalar value, which is the mean value of all the observations in the dataframe.

If we apply this method on a DataFrame object, then it returns a Series object which contains mean of values over the specified axis.

Syntax

Parameters

  • axis: {index (0), columns (1)}.
    This refers to the axis for a function that is to be applied.
  • skipna: It excludes all the null values when computing result.
  • level: It counts along with a particular level and collapsing into a Series if the axis is a MultiIndex (hierarchical),
  • numeric_only: It includes only int, float, boolean columns. If None, it will attempt to use everything, then use only numeric data. Not implemented for Series.

Returns

It returns the mean of the Series or DataFrame if the level is specified.

Example

Output

A     7.0
B    13.2
C     8.6
D    15.4
dtype: float64

Example2

Output

0       11.500000
1       16.000000
2       15.333333
3        9.333333
4       15.666667
dtype: float64





Latest Courses