Question: The idea is to build a function that assigns a schedule ( A , B , or C ) to the dates on a cycle

The idea is to build a function that assigns a schedule (A, B, or C) to the dates on a cycle of every 2 days(24hrs) switching to the next category in the list. It should repeat until the end date is reached. The starting date is 1/1/2022 to 12/31/2050.
The output must be:
1/1/2022= Schedule A
1/2/2022= Schedule A
1/3/2022= Schedule B
1/4/2022= Schedule B
1/5/2022= Schedule C
1/6/2022= Schedule C
And repeat again to Schedule A for 1/7
You can use this code to make work:
import pandas as pd
from datetime import datetime, timedelta
def generate_schedule(start_date, end_date):
# List of shifts
shifts =['A','B','C']
# Initialize variables
current_shift_index =0
current_date = start_date
date_list =[]
shift_list =[]
# Loop through the date range
while current_date <= end_date:
# Assign the current shift to the current date
date_list.append(current_date)
shift_list.append(shifts[current_shift_index])
# Move to the next shift and date
current_shift_index =(current_shift_index +1)% len(shifts)
current_date += timedelta(days=2)
# Create a DataFrame from the lists
schedule_df = pd.DataFrame({'Date': date_list, 'Shift': shift_list})
return schedule_df
# Set the start and end date
start_date = datetime(2022,1,1)
end_date = datetime(2050,12,31)
generate_schedule(start_date, end_date)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!