Search code examples
pythonloopsvariablesscipykruskals-algorithm

Test with many variables: I looking for quick method to introduce each variable in the test


I have some data and I need to compare the average but I am looking for quick method to introduce each sample in the test.

from scipy import stats

my_variables = ["a","b","c"]
my_variables[0] = [1,2,3]
my_variables[1] = [0,1,2]
my_variables[2] = [2,3,4]

Kruskal_Wallis_test= stats.kruskal(my_variables[0], my_variables[1], my_variables[2])

Would be it possible doing something like this?

Kruskal_Wallis_test= stats.kruskal(my_variables)

Solution

  • The * is used to unpack the argument list when the function is called, in this case it upacks your my_variables list.

    Here is how you should use * operator in your code,

    Kruskal_Wallis_test = stats.kruskal(*my_variables)
    

    which is identical to calling,

    Kruskal_Wallis_test= stats.kruskal(my_variables[0], my_variables[1], my_variables[2])