Facebook Page Twitter Page LinkedIn Page
× Pandas Tutorial Pandas Resources


The Pandas DataFrame - kurt() function is used to return the unbiased kurtosis over the specified axis. The syntax for using this function is mentioned below:

Syntax

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

Parameters

axis Optional. Specify {0 or 'index', 1 or 'columns'}. If 0 or 'index' kurtosis are generated for each column. If 1 or 'columns' kurtosis are generated for each row. Default: 0
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 Series. A str specifies the level name.
numeric_only Optional. Specify True to include only float, int or boolean data. Default: False

Return Value

Returns kurtosis of Series or DataFrame if a level is specified.

Example: Using kurt() column-wise on whole DataFrame

In the below example, a DataFrame df is created. The kurt() function is used to get the kurtosis for each column.

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(5, 3),
   index = pd.date_range('1/1/2018', periods=5),
   columns = ['col_A', 'col_B', 'col_C'])

print("The DataFrame is:")
print(df)

#kurtosis of all entries column-wise
print("\ndf.kurt() returns:")
print(df.kurt())

The output of the above code will be:

The DataFrame is:
               col_A     col_B     col_C
2018-01-01  0.343682  0.467754  0.731566
2018-01-02  0.588945  0.307980  0.397823
2018-01-03 -0.146330 -1.040161 -0.471874
2018-01-04 -0.732584  1.286889  0.022817
2018-01-05  0.422361 -0.613827  0.077464

df.kurt() returns:
col_A    0.194701
col_B   -1.141722
col_C    0.220942
dtype: float64

Example: Using kurt() row-wise on whole DataFrame

To get the row-wise sum, the axis parameter can set to 1. Consider the below example.

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(5, 4),
   index = pd.date_range('1/1/2018', periods=5),
   columns = ['col_A', 'col_B', 'col_C', 'col_D'])

print("The DataFrame is:")
print(df)

#kurtosis of all entries row-wise
print("\ndf.kurt(axis=1) returns:")
print(df.kurt(axis=1))

The output of the above code will be:

The DataFrame is:
               col_A     col_B     col_C     col_D
2018-01-01 -1.084664  0.845539 -0.435067  1.134583
2018-01-02 -1.717466  0.867263  0.427472 -0.721495
2018-01-03  1.054415  0.712278  0.149711  0.161991
2018-01-04 -0.147741  0.508162 -0.442463  0.004561
2018-01-05  2.680119  0.323035 -0.385693 -1.075277

df.kurt(axis=1) returns:
2018-01-01   -3.867439
2018-01-02   -2.201512
2018-01-03   -3.233237
2018-01-04    1.134319
2018-01-05    1.803169
Freq: D, dtype: float64

Example: Using kurt() on selected column

Instead of whole data frame, the kurt() function can be applied on selected columns. Consider the following example.

import pandas as pd
import numpy as np

df = pd.DataFrame(np.random.randn(5, 3),
   index = pd.date_range('1/1/2018', periods=5),
   columns = ['col_A', 'col_B', 'col_C'])

print("The DataFrame is:")
print(df)

#kurtosis of single column
print("\ndf['col_B'].kurt() returns:")
print(df["col_B"].kurt())

#kurtosis of multiple columns
print("\ndf[['col_B', 'col_C']].kurt() returns:")
print(df[["col_B", "col_C"]].kurt())

The output of the above code will be:

The DataFrame is:
               col_A     col_B     col_C
2018-01-01  0.219180 -0.912130  1.380747
2018-01-02  0.074638 -0.573183  1.960372
2018-01-03  0.586829 -0.440437  0.082292
2018-01-04  0.350402  0.591841  0.186822
2018-01-05 -0.277738  2.114145  0.084803

df['col_B'].kurt() returns:
0.979547037482

df[['col_B', 'col_C']].kurt() returns:
col_B    0.979547
col_C   -1.928345
dtype: float64

❮ Pandas DataFrame - Functions