I have a results_table as below:
sum_sq df F PR(>F)
ABC 4.13 4.0 337.2 2.53
Residual 4.45 110.0 NaN NaN
What I am trying to do to print out 'test positive' only if PR(>F) is greater than 1. I tried the below:
if results_table.loc[[1],'PR(>F)'] > 1:
print('test positive')
But I get the below error:
KeyError: "None of [Int64Index([1], dtype='int64')] are in the [index]"
Could someone please help me with how to do this?
CodePudding user response:
With loc use should row/col names
if results_table.loc[['ABC'],'PR(>F)'] > 1:
print('test positive')
CodePudding user response:
If you are actually trying to access a single value then this
if results_table.loc['ABC', 'PR(>F)'] > 1:
print('test positive')
or better this (.at[]
is optimised for this kind of access)
if results_table.at['ABC', 'PR(>F)'] > 1:
print('test positive')
should work.
The brackets here .loc[[1], 'PR(>F)']
or here .loc[['ABC'], 'PR(>F)']
make the result a series.