data1_new=data1[data1['成分累加和']>85.00 & data1['成分累加和']<105.00] 请帮我改正一下这个布尔索引
时间: 2023-12-25 12:03:59 浏览: 20
您好!根据您给出的布尔索引,需要将条件放在圆括号中,以避免运算符优先级错误。修改后的布尔索引如下所示:
```
data1_new = data1[(data1['成分累加和'] > 85.00) & (data1['成分累加和'] < 105.00)]
```
这样就可以正确地筛选出 '成分累加和' 列的值在 85.00 和 105.00 之间的数据行。如果有其他问题,请随时提问!
相关问题
优化这段代码 let that = this if( !/^\+?[1-9][0-9]*$/.test(that.data.cost) ){ wx.showToast({ title: '佣金必须为非零的正整数', icon: 'none', duration: 2000 }) return false; }else { if(that.data.cost > 100 && that.data.cost <= 300){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.3 }else if(that.data.cost > 300 && that.data.cost <= 500){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.6 }else if(that.data.cost > 500 && that.data.cost <= 1000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.8 }else if(that.data.cost > 1000 && that.data.cost <= 3000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 1 }else if(that.data.cost > 3000 && that.data.cost <= 5000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.6 }else if(that.data.cost > 5000 && that.data.cost <= 8000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.4 }else if(that.data.cost > 8000 && that.data.cost <= 10000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.2 }else if(that.data.cost > 10000 && that.data.cost <= 15000){ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0.1 }else{ missionSingleCostWeight = that.data.missionSingleCostWeight_D_value * 0 } if (that.data.cost > 0 && that.data.cost <= 500) { costPercent = 0.3 }else if (that.data.cost > 500 && that.data.cost <= 1000) { costPercent = 0.4 }else if (that.data.cost > 1000 && that.data.cost <= 2000) { costPercent = 0.5 }else if (that.data.cost > 2000 && that.data.cost <= 5000) { costPercent = 0.3 }else if (that.data.cost > 5000 && that.data.cost <= 10000) { costPercent = 0.2 }else if (that.data.cost > 10000 && that.data.cost <= 28000) { costPercent = 0.1 }else if (that.data.cost > 28000 && that.data.cost <= 80000) { costPercent = 0.05 }else if (that.data.cost > 80000 && that.data.cost <= 300000) { costPercent = 0 } }
){ wx.showToast({ title: '佣金不能超过100元', icon: 'none', duration: 2000 }) return false; }else{ return true; } }
可以将代码优化为:
const cost = this.data.cost;
if (/^\s*[1-9]\d*$/.test(cost)) {
const num = parseInt(cost);
if (num > 100) {
wx.showToast({
title: '佣金不能超过100元',
icon: 'none',
duration: 2000
})
return false;
} else {
return true;
}
} else {
wx.showToast({
title: '佣金必须为非零的正整数',
icon: 'none',
duration: 2000
})
return false;
}
rows_we_want1<-point.data$group>0&point.data$group==2
这行代码的意思是从 `point.data` 数据框中选择 `group` 列中值大于 0 且等于 2 的行,并将其赋值给 `rows_we_want1`。更具体地说,`point.data$group` 表示选择 `point.data` 数据框中的 `group` 列,`>` 表示大于号,`0` 表示 0,`&` 表示逻辑与,`==` 表示等于号,`2` 表示 2,所以 `point.data$group > 0 & point.data$group == 2` 表示 `group` 列中的值大于 0 且等于 2 的行。这个逻辑条件返回的是一个逻辑向量,其中 `TRUE` 表示满足条件的行,`FALSE` 表示不满足条件的行。然后,这个逻辑向量被用于选择 `point.data` 数据框中满足条件的行,最终结果是一个新的数据框,其中只包含 `group` 列中的值大于 0 且等于 2 的行。这个新的数据框被赋值给 `rows_we_want1` 变量。