Continuing the conversation in Can a variable number of arguments be passed to a function? , I'd like to learn how to generate a random number of arguments for a function in python 2.7.
In particular, while looping over various categories, I would like to pass an unkown number of array_like (or lists?) to scipy.stats.f_oneway
.
A simple example that works would be:
list_male = [34.316349, 34.32932, 34.27, 34.33905, 34.328951]
list_female = [34.61984, 34.34275, 34.6389, 34.44709, 34.51833]
f_oneway(list_male, list_female)
This works yielding
F_onewayResult(statistic=12.15815414713931, pvalue=0.0082363437299719927)
because I knew that my category gender
has only two classes male
, female
.
But what if I am running a loop of many categories and I do not want to predetermine specific lists? E.g, if a category column animal
in a pd.DataFrame
has an unknown number of classes. I would like within the loop to do something like df['animal'].unique().tolist()
and then create array_like (or whatever required) to feed to f_oneway
.