Reputation: 11
I'm trying to create a function to bucket data into deciles using a different field as the weight so I can have equal exposure buckets. In doing so I've created a simple example that I'm trying to get into 3 buckets. I'm really stumbling on the first part of it which is to get this while loop to work:
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)
My results are 0,0.
Thanks!
Upvotes: 0
Views: 33
Reputation: 659
Change:
while (c < target_sum) is True:
to:
while (c < target_sum):
Upvotes: 1