Rows until a number reaches zero [Python]

60
April 06, 2021, at 5:10 PM

I've been trying to find a solution to this problem for days, to no avail. Our warehouse asked for a way to calculate how many days it takes to process the incoming items, according to our forecast.

Table:

  • "daily capacity" = How many units are processed every day by the warehouse
  • "forecast units" = How many new units are supposed to arrive that day at the warehouse
  • "backlog" = How many units will be left in the backlog at the end of the day (what they couldn't process + what was left from previous days

Raw data: pd.DataFrame({'daily capacity': {'May 11': 27500, 'May 12': 27500, 'May 13': 0, 'May 14': 0, 'May 15': 0, 'May 16': 0, 'May 17': 27500, 'May 18': 27500, 'May 19': 27500}, 'forecast_units': {'May 11': 18007, 'May 12': 19305, 'May 13': 19122, 'May 14': 17292, 'May 15': 19592, 'May 16': 23393, 'May 17': 19000, 'May 18': 18539, 'May 19': 18531}, 'backlog': {'May 11': 0, 'May 12': 0, 'May 13': -19122, 'May 14': -36414, 'May 15': -56006, 'May 16': -79399, 'May 17': -70899, 'May 18': -61938, 'May 19': -52969}})

Problem: How to calculate, for each date, how many days it will take for the warehouse to process all units arrived that day. Each date the warehouse has different processing capacity, which must be taken into account.

Example: "The warehouse will take 3.6 days to process all units arrived on May 16".

Output: a column with the # of processing days for each date

What I've done so far: I tried with .cumsum(), while loops and creating some definition, but couldn't find a way that works.

Raw data:

Do you have any ideas or suggested solutions? Thanks :-)

EDIT:

Temporary solution I've found, let me know if it's correct:

dad.rename({'index':'dates'},axis=1,inplace=True)
def days_pr(bk,ind):
    temp = dad[ind:].copy()
    temp['cum cap'] = temp['daily capacity'].cumsum()
    i = ind
    cum_cp = temp['cum cap'][i]
    while cum_cp < abs(bk) and ind<7:
        i+=1
        cum_cp = temp['cum cap'][i]
    else:
        return (i-ind)
dad['days'] = [days_pr(bk,ind) for bk,ind in zip(dad['backlog'],dad.index)]
dad
READ ALSO
My notification is sent only when I start the app on some devices

My notification is sent only when I start the app on some devices

I have developed a notification that is sent every time a BroadcastReceiver is woken up by an AlarmMaganerWhen the receiver shows the notification it also takes care of activating the next notification

50
Calculate orientation angle of minutiae point [closed]

Calculate orientation angle of minutiae point [closed]

Want to improve this question? Update the question so it focuses on one problem only by editing this post

29
Add range in PHP scheduling system slots

Add range in PHP scheduling system slots

Helo! I am a beginner in programming and if anyone can help me change a code snippet I would appreciate itI have a scheduling system with time slots, where the slots are generated from variables with the start date until the end date

55