【发布时间】:2020-04-04 14:06:12
【问题描述】:
我有以下 new_correlation 数据框,其中包含以下输入
| Engagement Index | High Impact |
|------------------|-------------|
| 3.14 | 48.0 |
| 4.15 | 31.0 |
| 4.20 | 40.0 |
我的情况是
def priority_driver(corr, high_impact):
if corr > 0.4 & high_impact > 40:
return 'Sustenance'
elif corr > 0.4 & high_impact < 40:
return 'Improvement'
elif corr < 0.4 & high_impact > 40:
return 'Distraction'
elif corr < 0.4 & high_impact < 40:
return 'Low Focus'
我试过new_correlation['Priority of action'] = new_correlation.apply(lambda x: priority_driver(x['Engagement Index'], x['High Impact']), axis =1)
这给了我
TypeError: ("&: 'float' 和 'float' 不支持的操作数类型", '发生在索引 0')
所需输出:
| Engagement Index | High Impact | Priority of action |
|------------------|-------------|--------------------|
| 0.72 | 48.0 | Sustenance |
| 0.74 | 31.0 | Improvement |
| 0.78 | 40.0 | Sustenance |
【问题讨论】:
-
你需要括号来分隔条件
标签: python python-3.x pandas