I'm creating a Python program using pandas and datetime libraries that will calculate the pay from my casual job each week, so I can cross reference my bank statement instead of looking through payslips. The data that I am analysing is from the Google Calendar API that is synced with my work schedule. It prints the events in that particular calendar to a csv file in this format:
| Start | End | Title | Hours | |
|---|---|---|---|---|
| 0 | 02.12.2020 07:00 | 02.12.2020 16:00 | Shift | 9.0 |
| 1 | 04.12.2020 18:00 | 04.12.2020 21:00 | Shift | 3.0 |
| 2 | 05.12.2020 07:00 | 05.12.2020 12:00 | Shift | 5.0 |
| 3 | 06.12.2020 09:00 | 06.12.2020 18:00 | Shift | 9.0 |
| 4 | 07.12.2020 19:00 | 07.12.2020 23:00 | Shift | 4.0 |
| 5 | 08.12.2020 19:00 | 08.12.2020 23:00 | Shift | 4.0 |
| 6 | 09.12.2020 10:00 | 09.12.2020 15:00 | Shift | 5.0 |
As I am a casual at this job I have to take a few things into consideration like penalty rates (baserate, after 6pm on Monday - Friday, Saturday, and Sunday all have different rates). I'm wondering if I can analyse this csv using datetime and calculate how many hours are before 6pm, and how many after 6pm. So using this as an example the output would be like:
| Start | End | Title | Hours | |
|---|---|---|---|---|
| 1 | 04.12.2020 15:00 | 04.12.2020 21:00 | Shift | 6.0 |
| Start | End | Title | Total Hours | Hours before 3pm | Hours after 3pm | |
|---|---|---|---|---|---|---|
| 1 | 04.12.2020 15:00 | 04.12.2020 21:00 | Shift | 6.0 | 3.0 | 3.0 |
I can use this to get the day of the week but I'm just not sure how to analyse certain bits of time for penalty rates:
df['day_of_week'] = df['Start'].dt.day_name()
I appreciate any help in Python or even other coding languages/techniques this can be applied to:)
Edit: This is how my dataframe is looking at the moment
| Start | End | Title | Hours | day_of_week | Pay | week_of_year | |
|---|---|---|---|---|---|---|---|
| 0 | 2020-12-02 07:00:00 | 2020-12-02 16:00:00 | Shift | 9.0 | Wednesday | 337.30 | 49 |
EDIT In response to David Erickson's comment.
| value | variable | bool | |
|---|---|---|---|
| 0 | 2020-12-02 07:00:00 | Start | False |
| 1 | 2020-12-02 08:00:00 | Start | False |
| 2 | 2020-12-02 09:00:00 | Start | False |
| 3 | 2020-12-02 10:00:00 | Start | False |
| 4 | 2020-12-02 11:00:00 | Start | False |
| 5 | 2020-12-02 12:00:00 | Start | False |
| 6 | 2020-12-02 13:00:00 | Start | False |
| 7 | 2020-12-02 14:00:00 | Start | False |
| 8 | 2020-12-02 15:00:00 | Start | False |
| 9 | 2020-12-02 16:00:00 | End | False |
| 10 | 2020-12-04 18:00:00 | Start | False |
| 11 | 2020-12-04 19:00:00 | Start | True |
| 12 | 2020-12-04 20:00:00 | Start | True |
| 13 | 2020-12-04 21:00:00 | End | True |
| 14 | 2020-12-05 07:00:00 | Start | False |
| 15 | 2020-12-05 08:00:00 | Start | False |
| 16 | 2020-12-05 09:00:00 | Start | False |
| 17 | 2020-12-05 10:00:00 | Start | False |
| 18 | 2020-12-05 11:00:00 | Start | False |
| 19 | 2020-12-05 12:00:00 | End | False |
| 20 | 2020-12-06 09:00:00 | Start | False |
| 21 | 2020-12-06 10:00:00 | Start | False |
| 22 | 2020-12-06 11:00:00 | Start | False |
| 23 | 2020-12-06 12:00:00 | Start | False |
| 24 | 2020-12-06 13:00:00 | Start | False |
| 25 | 2020-12-06 14:00:00 | Start | False |
| 26 | 2020-12-06 15:00:00 | Start | False |
| 27 | 2020-12-06 6:00:00 | Start | False |
| 28 | 2020-12-06 17:00:00 | Start | False |
| 29 | 2020-12-06 18:00:00 | End | False |
| 30 | 2020-12-07 19:00:00 | Start | False |
| 31 | 2020-12-07 20:00:00 | Start | True |
| 32 | 2020-12-07 21:00:00 | Start | True |
| 33 | 2020-12-07 22:00:00 | Start | True |
| 34 | 2020-12-07 23:00:00 | End | True |
| 35 | 2020-12-08 19:00:00 | Start | False |
| 36 | 2020-12-08 20:00:00 | Start | True |
| 37 | 2020-12-08 21:00:00 | Start | True |
| 38 | 2020-12-08 22:00:00 | Start | True |
| 39 | 2020-12-08 23:00:00 | End | True |
| 40 | 2020-12-09 10:00:00 | Start | False |
| 41 | 2020-12-09 11:00:00 | Start | False |
| 42 | 2020-12-09 12:00:00 | Start | False |
| 43 | 2020-12-09 13:00:00 | Start | False |
| 44 | 2020-12-09 14:00:00 | Start | False |
| 45 | 2020-12-09 15:00:00 | End | False |
| 46 | 2020-12-11 19:00:00 | Start | False |
| 47 | 2020-12-11 20:00:00 | Start | True |
| 48 | 2020-12-11 21:00:00 | Start | True |
| 49 | 2020-12-11 22:00:00 | Start | True |