Pandas Series kurt() Function:
Pandas kurtosis: The kurt() method of the Pandas Series gets the unbiased kurtosis over the given axis.
Syntax:
Series.kurt(axis=None, skipna=None, level=None, numeric_only=None)
Parameters
axis: This is optional. It indicates 0 or ‘index’. This is the axis on which the function will be applied.
skipna: This is optional. When computing the result, specify True to exclude NA/null values. The default value is True.
level: This is optional. It indicates the level (int or str). If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar. The level name is specified by str.
numeric_only: This is optional. Pass True to include just float, int, or boolean data. False by default
Return Value:
If a level is given, it returns a scalar or a series. The unbiased kurtosis over the given axis is returned by this kurt() method of the Pandas Series.
- Python Pandas Series var() Function
- Python Pandas Series skew() Function
- Python Pandas Series std() Function
Pandas Series kurt() Function in Python
Example1
Approach:
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Import numpy module using the import keyword. import numpy as np idx = pd.MultiIndex.from_arrays([ ['rand', 'rand', 'rand', 'rand', 'randn', 'randn', 'randn', 'randn']], names=['DataType']) x = pd.Series(np.append(np.random.rand(4), np.random.randn(4)), index=idx) print("The Series contains:") print(x) #kurtosis of all values in the series print("\nx.kurt() returns:") print(x.kurt()) #kurtosis of all values within given level print("\nx.kurt(level='DataType') returns:") print(x.kurt(level='DataType')) print("\nx.kurt(level=0) returns:") print(x.kurt(level=0))
Output:
Example2
Approach:
- Import pandas module using the import keyword.
- Pass some random key-value pair(dictionary), index list as arguments to the DataFrame() function of the pandas module to create a dataframe.
- Store it in a variable.
- Print the given dataframe.
- Apply kurt() function on the student_marks column of the dataframe to get the kurtosis of all the elements of the student_marks column and print the result.
-
The Exit of the Program.
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Pass some random key-value pair(dictionary), index list as arguments to the # DataFrame() function of the pandas module to create a dataframe # Store it in a variable. data_frme = pd.DataFrame({ "student_rollno": [1, 2, 3, 4], "student_marks": [80, 35, 25, 90]}, index= ["virat", "nick" , "jessy", "sindhu"] ) # Print the given dataframe print("The given Dataframe:") print(data_frme) print() # Apply kurt() function on the student_marks column of the dataframe to # get the kurtosis of all the elements of the student_marks column # and print the result. print("The kurtosis of all the elements of student_marks column of a dataframe:") print(data_frme["student_marks"].kurt())
Output:
The given Dataframe: student_rollno student_marks virat 1 80 nick 2 35 jessy 3 25 sindhu 4 90 The kurtosis of all the elements of student_marks column of a dataframe: -5.07072