将多个参数传递给 python 中的 scipy 统计函数



我正在尝试将多个参数传递给python中的一些scipy stats函数,例如stats.kruskal,但问题是有时我只有三个参数,有时我得到了更多,我不知道如何动态传递它。这是我到目前为止得到的:

dependent_variable = dataset[attributes[0]]
independent_variable = dataset[attributes[1]]
dependent_variable_values = dataset[attributes[0]].unique()
i = 0
stre = ''
temp = []
for item in dependent_variable_values:
temp.append(dataset.loc[dataset[attributes[0]] == dependent_variable_values[i]])
i += 1
for i in range(i):
stre = temp[i]['Oceny']
i = i - 1

我的第一个想法是使用这些数组创建字符串,但它不是那样工作的。

这是相同代码的示例,但自动化程度较低,工作正常,但正如我之前所说,我不会总是只得到三个参数并且非常了解数据。我希望下面的这段代码更自动地处理每个数据。

a = dataset['Group']
b = dataset['Mark']
c = dataset.loc[dataset['Group'] == '1'] #here I know that group contains only 3 possibly values 1, 2, 3 but I will know that in every case
d = dataset.loc[dataset['Group'] == '2']
e = dataset.loc[dataset['Group'] == '3']
testy = [c['Mark'], d['Mark'], e['Mark']] #marks for group 1, 2, 3

使用func(*args)func(*position_args, **keyword_args)

https://docs.python.org/3/faq/programming.html#how-can-i-pass-optional-or-keyword-parameters-from-one-function-to-another

最新更新