ANOVA for groups within a dataframe using scipy

Viewed 9085

I have a dataframe as follows. I need to do ANOVA on this between three conditions. The dataframe looks like:

data0 = pd.DataFrame({'Names': ['CTA15', 'CTA15', 'AC007', 'AC007', 'AC007','AC007'], 
    'value': [22, 22, 2, 2, 2,5], 
    'condition':['NON', 'NON', 'YES', 'YES', 'RE','RE']})

I need to do ANOVA test between YES and NON, NON and RE and YES and RE, conditions from conditions for Names. I know I could do it like this,

NON=df.query('condition =="NON"and Names=="CTA15"')
no=df.value
YES=df.query('condition =="YES"and Names=="CTA15"')    
Y=YES.value

Then perform one way ANOVA as following,

    from scipy import stats                
    f_val, p_val = stats.f_oneway(no, Y)            
    print ("One-way ANOVA P =", p_val )

But would be great if there is any elegant solution as my initial data frame is big and has many names and conditions to compare between

1 Answers
Related