0

I am a novice in python and trying to perform the Kruskal Wallis test for multiple columns divided into two Groups (C2 & S1).

Till now, I have been able to do the Kruskal Wallis test for a single column with the following code. (I collected through the internet)

import pandas as pd
df =pd.read_excel( 'C2_S1_sorted_2.xlsx')

#collected through internet
import scipy.stats as ss
data = [df.loc[ids, '3-HYDROXYPHENYLACETATE-DEGRADATION-PWY: 4-hydroxyphenylacetate degradation'].values for ids in df.groupby('Group').groups.values()]
H, p = ss.kruskal(*data)
p

I tried to use "while loop" to loop over all columns but till now not been able to do so. I also went through almost all questions related to this in StackOverflow, but I am unable to solve my problem.

Can anyone please help me in doing this? I am sorry if this is a very basic question.

Below is how my data looks like.

Group   1CMET2-PWY: N10-formyl-tetrahydrofolate biosynthesis    3-HYDROXYPHENYLACETATE-DEGRADATION-PWY: 4-hydroxyphenylacetate degradation  7ALPHADEHYDROX-PWY: cholate degradation (bacteria, anaerobic)
C2  889.944 0   0
C2  931.451 0   0
C2  795.362 0   0
C2  840.724 0   0
C2  732.173 0   0
C2  908.025 0.843261    0
C2  733.818 0.518661    0
C2  842.462 1.82225 0
C2  843.887 0   0
C2  823.395 0   0
C2  713.35  0.699201    0.534327
C2  859.136 0.604455    0
C2  871.477 0   0
C2  763.695 0   0
C2  835.966 0   0
C2  781.925 0   0
C2  1010.87 0   0
C2  936.106 0   0
C2  738.947 1.9034  0
C2  988.541 0   0
S1  838.256 0   0
S1  758.363 0   0
S1  1022.51 0   0
S1  1016.61 0   0
S1  908.64  0   0
S1  941.786 0   0
S1  999.038 0   0
S1  914.317 0   0
S1  1053.07 0   0
S1  876.61  0   0
S1  793.693 0   0
S1  916.2   0   0
S1  1108.61 0   0
S1  938.456 0   0
S1  825.406 0   0
S1  1332.52 0   0
S1  1198.65 0   0
S1  1005.4  0   0
S1  826.529 0   0
S1  1170.82 0.624429    0
bcube
  • 1
  • Hi. I did it using R.4.1. I took code from " https://stackoverflow.com/questions/63293995/how-to-loop-bartlett-test-and-kruskal-tests-for-multiple-columns-in-a-dataframe " – bcube Jul 07 '21 at 15:02

0 Answers0