Pandas DataFrame kurtosis() Method
In this tutorial, we will learn the Python pandas DataFrame.kurtosis()
method. This method returns unbiased kurtosis over the requested axis.
Kurtosis obtained using Fisher’s definition of kurtosis (kurtosis of normal == 0.0). Normalized by N-1. The below shows the syntax of the DataFrame.kurtosis()
method.
Syntax
DataFrame.kurtosis(axis=None, skipna=None, level=None, numeric_only=None, **kwargs)
Parameters
axis: {index (0), columns (1)}. Axis for the method to be applied on.
skipna: bool, default True. Exclude NA/null values when computing the result.
level: int or level name, default None. If the axis is a MultiIndex (hierarchical), count along with a particular level, collapsing into a Series.
numeric_only: bool, default None. Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.
**kwargs: Additional keyword arguments to be passed to the method.
Example: The DataFrame.kurtosis()
Method
The following code shows the example of the DataFrame.kurtosis()
method along the axis=0. It returns unbiased kurtosis based on the specified axis, 0 represents the index and 1 for the columns.
#importing pandas as pd
import pandas as pd
#creating DataFrame
df=pd.DataFrame({"A":[55,60,74,50],"B":[30,55,40,47],"C":[12,55,44,66]})
print("-----------The DataFrame is-------")
print(df)
print("-------------------------------")
print(df.kurtosis(axis=0))
Once we run the program we will get the following output.
-----------The DataFrame is-------
A B C
0 55 30 12
1 60 55 55
2 74 40 44
3 50 47 66
-------------------------------
A 1.307557
B -0.466318
C 1.414727
dtype: float64
Example: The DataFrame by excluding null values
The following code shows the example of the DataFrame.kurtosis()
method by excluding null values. The skipna argument skips the null values and returns a dataframe.
#importing pandas as pd
import pandas as pd
#creating DataFrame
df=pd.DataFrame({"A":[55,60,None,60,50],"B":[42,30,None,40,47],"C":[None,75,55,44,66]})
print(df.kurtosis(axis=0,skipna=True))
Once we run the program we will get the following output.
A -1.289256
B 1.704496
C -1.441136
dtype: float64
Example: The DataFrame by including only numeric values
The following code shows the example of the DataFrame.kurtosis()
method that returns a dataframe including only numeric values.
#importing pandas as pd
import pandas as pd
#creating DataFrame
df=pd.DataFrame({"A":[55,60,None,60,50],"B":[42,30,None,40,47],"C":[None,75,55,44,66]})
print(df.kurtosis(axis=0,numeric_only=True))
Once we run the program we will get the following output.
A -1.289256
B 1.704496
C -1.441136
dtype: float64
Conclusion
In this tutorial, we learned the Python pandas DataFrame.kurtosis()
method. We learned the syntax and applying this method on the DataFrame to understood the DataFrame.kurtosis()
method.