python 价值争论
python argument on value
我有一个 results_table 如下:
sum_sq df F PR(>F)
ABC 4.13 4.0 337.2 2.53
Residual 4.45 110.0 NaN NaN
仅当 PR(>F) 大于 1 时,我才尝试打印出 'test positive'。我尝试了以下操作:
if results_table.loc[[1],'PR(>F)'] > 1:
print('test positive')
但是我得到以下错误:
KeyError: "None of [Int64Index([1], dtype='int64')] are in the [index]"
有人可以帮我解决这个问题吗?
with loc use should row/col names
if results_table.loc[['ABC'],'PR(>F)'] > 1:
print('test positive')
如果您实际上是想访问一个单个值,那么这个
if results_table.loc['ABC', 'PR(>F)'] > 1:
print('test positive')
或更好(.at[]
针对此类访问进行了优化)
if results_table.at['ABC', 'PR(>F)'] > 1:
print('test positive')
应该可以。
此处 .loc[[1], 'PR(>F)']
或此处 .loc[['ABC'], 'PR(>F)']
的括号使结果成为一个系列。
我有一个 results_table 如下:
sum_sq df F PR(>F)
ABC 4.13 4.0 337.2 2.53
Residual 4.45 110.0 NaN NaN
仅当 PR(>F) 大于 1 时,我才尝试打印出 'test positive'。我尝试了以下操作:
if results_table.loc[[1],'PR(>F)'] > 1:
print('test positive')
但是我得到以下错误:
KeyError: "None of [Int64Index([1], dtype='int64')] are in the [index]"
有人可以帮我解决这个问题吗?
with loc use should row/col names
if results_table.loc[['ABC'],'PR(>F)'] > 1:
print('test positive')
如果您实际上是想访问一个单个值,那么这个
if results_table.loc['ABC', 'PR(>F)'] > 1:
print('test positive')
或更好(.at[]
针对此类访问进行了优化)
if results_table.at['ABC', 'PR(>F)'] > 1:
print('test positive')
应该可以。
此处 .loc[[1], 'PR(>F)']
或此处 .loc[['ABC'], 'PR(>F)']
的括号使结果成为一个系列。