I have a dataframe df of the form
class_1_frequency class_2_frequency
group_1 20 10
group_2 60 25
..
group_n 50 15
Suppose class_1 has a total of 70 members and class_2 has 30.
For each row (group_1, group_2,..group_n) I want to create contingency tables (preferably dynamically) and then carry out a chisquare test to evaluate p-values.
For example, for group_1, the contingency table under the hood would look like:
class_1 class_2
group_1_present 20 10
group_1_absent 70-20 30-10
Also, I know scipy.stats.chi2_contingency() is the appropriate function for chisquare, but I am not able to apply it to my context. I have looked at previously discussed questions such as: here and here.
What is the most efficient way to achieve this?