我正在尝试根据另一列的值为一列指定一些标签。'Percentage_delay'
列的值的范围从0到1。如果'Percentage_delay'
列的值大于0.75,则'Labels'
列上的相应值应为'high'
,如果小于0.75且大于0.5'medium'
,如果小于0.5'low'
我想出了这个密码:
for i in number_delay_aiport['Percentage_delay']:
if i >= 0 and i < 0.25:
number_delay_aiport['Labels'] = 'low'
if i >= 0.25 and i < 0.75:
number_delay_aiport['Labels'] = 'medium'
if i >= 0.75 and i <= 1:
number_delay_aiport['Labels'] = 'high'
输出错误,因为我只有Label == 'high'
:
Output
如果我使用'return'
函数,也会发生同样的情况
你能告诉我为什么会这样吗
将for循环更改为枚举for循环,并在标签上使用
iloc
:或者更好的方法是,使用
apply
函数可以执行以下操作:相关问题 更多 >
编程相关推荐