here am using ztest
built-in function within statsmodels
to do single hypothesis test , however If I want to run many separate hypothesis tests - on many different columns
- to test say the difference between two medians
or two means
, then it becomes cumbersome when doing it one by one , Is there faster and efficient way (memory and time wise) to run n
number of these tests , to be more specific, say we have a dataframe
of n columns
, and I wanna test the difference between a mean or median return of certain trading days or (sequence of them) for a certain ticker versus the overall mean of that ticker over some period of time say 5 years (with daily values), now in the standard case , one would use
from statsmodels.stats.weightstats import ztest
ztest_Score, p_value = ztest(df_altenative['symbol is here'], df_null , alternative='two-sided')
where of course df_null above is scalar quantity(say daily average return for the entire period), and df_alternative is a column
within a larger dataframe
of tickers , and it holds the mean or median of your sequence trading days
, then , how one can do this iterative procedure in just one line of code if possible where it goes over each one of these separate columns within my data frame and the corresponding associated mean or median value and compare them to decide on which hypothesis to be rejected or not ?
best regards