0

This is the dataframe I have. I am trying to associate number of hours spent on a project per week with the corresponding weekstart and weekend time frame.

Entry                               Exit
2019-07-01 09:56:00                 2020-06-29 11:54:00
2019-07-13 07:43:00                 2020-06-26 15:38:00 
2019-07-18 13:59:00                 2020-06-24 11:57:00

I have used this function to find weekstart and weekend:

def find_week_start(date): 
    if date.weekday() == 6:
        return date
    else: 
        week_start = (date- datetime.timedelta(days = date.weekday() + 1))
        return week_start
#function to find last day of week (Saturday)
def find_week_end(date):
    week_end = find_week_start(date) + datetime.timedelta(days = 6)
    return week_end

But I need the hours to associate with the weeks in between the two periods as well.

It Needs to look something like this (using the first row of the data listed above as an example).

WeekStart               WeekEnd                 Hours 
2019-06-30 00:00:00     2019-07-06 23:59:59     134.066
2019-07-07 00:00:00     2019-07-13 23:59:59     168
2019-07-14 00:00:00     2019-07-20 23:59:59     168 
... 
... 
... 
... 
2020-06-28 00:00:00     2020-07-04 23:59:59     35.9

Eventually this will turn into a groupby function by WeekStart and WeekEnd, summing the total hour for each week.

  • 1
    I don't understand how you would get week hours from your three rows of data, entry and exit are not even in the same week – RichieV Sep 03 '20 at 17:17
  • So that one person stayed the whole year. The solution I need, which is the last table on the bottom, is what I need out of that one instance from when they entered to when they exited. – user14215903 Sep 03 '20 at 23:48

0 Answers0