Hello I am very new to programming
I have a big dataframe from which I want to run a t student using test_ind which performs a mean difference of quantitative variable of two groups. For example comparing the oxygen levels of a control group vs a treatment group The thing is that I have a lot of quantitative variables to run and I want to develop a function which
- Takes the data of the groups
- Runs the t stat
- Put the data in a data frame
I have this code but I do not know how to add a loop into it
#This part grabs the variables from the dataframe
grupoA= df[df['Grupo ']=='A']['Sat de oxigeno 3']
grupoB= df[df['Grupo ']=='B']['Sat de oxigeno 3']
#This one runs the t stat
x18=ttest_ind(grupoA, grupoB)
#This one puts the results in a dataframe
tablaT = pd.DataFrame((x7,x8,x9, x10, x11,x12,x13,x14,x15,x16,x17,x18),columns='T-test p-value'.split(),index='Frecuencia1 Frecuencia2 Frecuencia3 PresionSistolica1 PresionSistolica2 PresionSistolica3 PresionDiastolica1 PresionDiastolica2 PresionDiastolica3 SaturacionOx1 SaturacionOx2 SaturacionOx3'.split())
tablaT ```
The thing is that I would like to have a function that I enter the variable from the dataframe and runs the code instead of doing it constantly
Thank you very much