You can download this code by clicking the button below.
This code is now available for download.
This function performs the Shapiro-Wilk test to check if the data follows a normal distribution. It takes a pandas.Series object as input and returns a tuple containing the statistic and the p-value from the test.
Technology Stack : pandas, scipy
Code Type : Function
Code Difficulty : Intermediate
import numpy as np
import pandas as pd
from scipy.stats import shapiro
def test_normality(data):
"""
Test the normality of the data using Shapiro-Wilk test.
Parameters:
data (pandas.Series): The data to be tested for normality.
Returns:
tuple: A tuple containing the p-value and the statistic from the test.
"""
# Perform Shapiro-Wilk test
stat, p_value = shapiro(data)
return stat, p_value