import pandas as pd

def es_cohen_w(chi2, n):
    '''
    Cohen's w
     
    This function will calculate Cohen's w
    
    Parameters
    ----------
    chi2 : the chi-square test statistic
    n : the sample size
        
    Returns
    -------
    testResults : Pandas dataframe with Cohen's w, and classification
   
    Notes
    -----
    Classification based on Cohen (1988, p. 227)
    
    Author
    ------
    Made by P. Stikker
    
    Please visit: https://PeterStatistics.com
    
    YouTube channel: https://www.youtube.com/stikpet
    
    '''
    
    w = (chi2 / n)**0.5
    
    #interpretation (Cohen, 1988, p. 227)
    if (abs(w) < 0.1):
        qual = "negligible"
    elif (abs(w) < 0.3):
        qual = "small"
    elif (abs(w) < 0.5):
        qual = "medium"
    else:
        qual = "large"
        
    testResults = pd.DataFrame([[w, qual]], columns=["Cohen's w", "Classification"])
        
    pd.set_option('display.max_colwidth', None)
    
    return testResults

#Examples
chi2 = 3.105263
n = 19

es_cohen_w(chi2, n)