【发布时间】:2021-06-19 08:24:30
【问题描述】:
我正在尝试根据多个列“类”和“值”为“百分比”列分配一个值
以下是包含我的数据框的链接: https://filebin.net/fo2wk7crmwf0fycc
这是我要应用的逻辑:
If df['Class'] equals 2 or 3, and if df['Value'] is less than 0.5, set df['Percentage'] to 0
If df['Class'] equals 2 or 3, and if df['Value'] is > 0.5 and <= 0.7, set df['Percentage'] to 0.25
If df['Class'] equals 2 or 3, and if df['Value'] is > 0.7 and <= 0.9, set df['Percentage'] to 0.5
Else set df['Percentage'] to 1
下面是我正在寻找的输出示例:
| Class | Value | Percentage |
|---|---|---|
| 2 | 0.01 | 0 |
| 2 | 0.6 | 0.25 |
| 3 | 0.9 | 0.5 |
| 3 | 3 | 1 |
谢谢
【问题讨论】:
标签: python pandas dataframe if-statement conditional-statements