我正在尝试根据多个列 'Class' 和 'Value' 为列 'Percentage' 分配一个值。
以下是包含数据框的链接: 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
下面是我所期望的输出示例:
分类 | 数值 | 百分比 |
---|---|---|
2 | 0.01 | 0 |
2 | 0.6 | 25% |
3 | 0.9 | 50% |
3 | 3 | 100% |