I am not familiar with any special requirements of the Kruskal-Wallis test, but you can access these grouped arrays by putting them into the dictionary as follows:
groupednumbers = {}
for grp in df['group'].unique():
groupednumbers[grp] = df['numbers'][df['group']==grp].values
print(groupednumbers)
*** {'c': array([2, 5, 8]), 'b': array([1, 4, 7]), 'a': array([0, 3, 6])}
That is, you get your vectors, explicitly calling groupednumbers['a'], etc., or through a list:
args = groupednumbers.values()
... or if you need them in order:
args = [groupednumbers[grp] for grp in sorted(df['group'].unique())]
And then call
stats.kruskal(*args)
Or, if you need actual listings, you can do that list(df['numbers'][...].values.)
source
share