我已经阅读了许多线程(here和here)和文档(here和here)。但是,我无法使它正常工作。我收到
的错误AxisError: axis 0 is out of bounds for array of dimension 0
谢谢。
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)
答案 0 :(得分:1)
将def
中的列表理解替换为:
cols = [df[x] for x in cols_of_interest]