0

I've read up on a number of threads (here and here) and the docs (here and here). However, I can't get this to work. I get an error of

AxisError: axis 0 is out of bounds for array of dimension 0

Thanks.

import pandas as pd
from scipy.stats import levene

data = {'A': [1,2,3,4,5,6,7,8],
        'B': [9,10,11,12,13,14,15,16],
        'C': [1,2,3,4,5,6,7,8]}
df3 = pd.DataFrame(data, columns=['A', 'B','C'])

print(levene(df3['A'], df3['C'])) # this works as intended

cols_of_interest = ['A','C'] # my requirement could make this any combination

# function to pass through arguments into Levene test
def func(df,cols_of_interest):
    cols = [col for col in 'df.'+df[cols_of_interest].columns] # my strategy to mimic the arguments
    lev = levene(*cols)
    print(lev)

func(df3,cols_of_interest)
June
  • 720
  • 10
  • 22

1 Answers1

1

Replace your list comprehension inside def with:

cols = [df[x] for x in cols_of_interest]
gyoza
  • 2,112
  • 2
  • 12
  • 18