Pandas Tutorial Pandas Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

Pandas Series - kurt() function

The Pandas Series - kurt() function returns the unbiased kurtosis over the specified axis. The syntax for using this function is mentioned below:


Series.kurt(axis=None, skipna=None, level=None, numeric_only=None)


axis Optional. Specify {0 or 'index'}. Specify axis for the function to be applied on.
skipna Optional. Specify True to exclude NA/null values when computing the result. Default is True.
level Optional. Specify level (int or str). If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar. A str specifies the level name.
numeric_only Optional. Specify True to include only float, int or boolean data. Default: False

Return Value

Returns scalar or Series if a level is specified.

Example: Using kurt() on a Series

In the example below, the kurt() function is used to get the kurtosis of a given series.

import pandas as pd
import numpy as np

idx = pd.MultiIndex.from_arrays([
    ['rand', 'rand', 'rand', 'rand', 'randn', 'randn', 'randn', 'randn']],

x = pd.Series(np.append(np.random.rand(4), np.random.randn(4)), index=idx)

print("The Series contains:")

#kurtosis of all values in the series
print("\nx.kurt() returns:")

#kurtosis of all values within given level
print("\nx.kurt(level='DataType') returns:")
print("\nx.kurt(level=0) returns:")

The output of the above code will be:

The Series contains:
rand        0.030591
rand        0.183242
rand        0.687058
rand        0.277481
randn      -0.288712
randn      -0.878824
randn      -1.572509
randn      -0.948994
dtype: float64

x.kurt() returns:

x.kurt(level='DataType') returns:
rand     1.923868
randn    1.416024
dtype: float64

x.kurt(level=0) returns:
rand     1.923868
randn    1.416024
dtype: float64

Example: Using kurt() on selected series in a DataFrame

Similarly, the kurt() function can be applied on selected series/column of a given DataFrame. Consider the following example.

import pandas as pd
import numpy as np

df = pd.DataFrame({
  "Bonus": [5, 3, 2, 4],
  "Last Salary": [58, 60, 63, 57],
  "Salary": [60, 62, 65, 59]},
  index= ["John", "Marry", "Sam", "Jo"]

print("The DataFrame is:")

#kurtosis of all values of 'Salary' series
print("\ndf['Salary'].kurt() returns:")

The output of the above code will be:

The DataFrame is:
       Bonus  Last Salary  Salary
John       5           58      60
Marry      3           60      62
Sam        2           63      65
Jo         4           57      59

df['Salary'].kurt() returns:

❮ Pandas Series - Functions