Need a quick way to apply a t-test to multiple groups and multiple variables. Let's assume I have a table like this:
df = pd.DataFrame({'group': 'a a b b'.split(), 'B': [1,2,3,4], 'C': [4,6, 5,10]})
print(df)
The group column has a control and variant. a = control, b = variants
Column B is a metric. Column C is another metric and I have many more metrics. I need to loop through N columns.
I want to group by my 'group' column so I'm always comparing my control to one of the variants in column B and apply the ttest_ind
function.
Is there a solution with for loops or .apply() ? Ideally, I'd just like to do something like:
df.groupby('group').apply(ttest_ind(control, n columns)