I have a pandas series which looks like this:
dish_name
Chiken Biryani 3
Mutton Biryani 1
Paneer Biryani 4
Paneer Pulav 2
sandwitch 2
I am calculating (3/(3+1+4+2+2) then second element (1/(3+1+4+2+2) and so on till the end of series.. Which I am doing it with following code in python:
def dish_push(dish_data):
dish_number = len(dish_data)
for i in range(dish_number):
dish = ((dish_data[i])/(dish_data[0:dish_number].sum()))*100
return dish
But when I pass a series to this function it outputs only the last value.
dish_push(dish_quantity_sold)
Out[291]: 16.666666666666664
Where as I am expecting like this..
25.0
8.33333333333
33.3333333333
16.6666666667
16.6666666667
Am I doing some mistake in return statement? Why is it printing the last value? please help.
dish
on each iteration you should append to a list or similar container and return this, also this is very similar to your previous question, what's wrong with(s/s.sum()) * 100
?100*df.x/df.x.sum()