While循环出现问题

时间:2018-10-14 15:07:11

标签: python while-loop do-while

我正在尝试创建一个函数,使用不同的字段作为权重将数据存储到decil中,这样我就可以拥有相等的曝光存储桶。为此,我创建了一个简单的示例,试图将其分为3个类。我真的在它的第一部分绊脚石,这是为了使while循环正常工作:

df = pd.DataFrame({'A': [1,2,3,4,5,6,7,8,9,10], 'B': [5,7,9,11,15,19,25,4,3,2]})

bin_size = .333
target_sum = bin_size * df.agg({'B': 'sum'})
increment = 1

bot_try = 0
top_try = 0
c = 0

while (c < target_sum) is True:

    a = df[df['A'] > bot_try]
    b = a[a['A'] <= top_try]
    c = b.agg({'B': 'sum'})
    top_try = top_try + increment

else:

    print(c)
    print(top_try)

我的结果是0,0。

谢谢!

1 个答案:

答案 0 :(得分:1)

更改:

while (c < target_sum) is True:

收件人:

while (c < target_sum):
相关问题