I thought this would be an interesting exercise, so I attempted it. Let me know if you have any questions.
import pandas as pd
import datetime
# Initial Data
list = ['Correct','2022-07-12 19:00:00','2022-07-15 11:00:00']
# Create Dataframe
df = pd.DataFrame(data = [list],columns=['State','StartDate','EndDate'])
# Convert Dates to Datetime
df['StartDate'] = pd.to_datetime(df['StartDate'])
df['EndDate'] = pd.to_datetime(df['EndDate'])
# Create Dataframe for New Results
df2 = pd.DataFrame(data=None,columns=['State','StartDate','EndDate'])
# Iterate through inital dataframe rows
for n,m in df.iterrows():
# For each row, determine the number of days between the start and end date
num_days = (df['EndDate'].dt.day - df['StartDate'].dt.day)
# Iterating number of days between the start and end date
for a in range(0,num_days[0]+1):
# For the first day
if a ==0:
# Create a list
list = []
# Populate the list with the values of interest
list.append('Correct') # State
list.append(df['StartDate'].iloc[n]) # Startdate
list.append((df['StartDate'].iloc[n] + datetime.timedelta(days=1 )).normalize()) # EndDate
# Append values to new dataframe
df2 = pd.concat([df2,pd.DataFrame([list],columns=['State','StartDate','EndDate'])])
# Get the next date
nextdate = (df['StartDate'].iloc[n] + datetime.timedelta(days=1 )).normalize()
# For the last day
elif a == num_days[0]:
list = []
# Populate the list with the values of interest
list.append('Correct') # State
list.append(nextdate) # Startdate
list.append(df['EndDate'][n]) # EndDate
# Append values to new dataframe
df2 = pd.concat([df2,pd.DataFrame([list],columns=['State','StartDate','EndDate'])])
# For all the dates inbetween
else:
list = []
# Populate the list with the values of interest
list.append('Correct') # State
list.append(nextdate) # Startdate
list.append((nextdate + datetime.timedelta(days=1 )).normalize()) # EndDate
# Append values to new dataframe
df2 = pd.concat([df2, pd.DataFrame([list], columns=['State', 'StartDate', 'EndDate'])])
# Get the next date
nextdate = (nextdate + datetime.timedelta(days=1 )).normalize()
# Convert Dates in New Dataframe to Datetime
df2['StartDate'] = pd.to_datetime(df2['StartDate'])
df2['EndDate'] = pd.to_datetime(df2['EndDate'])
# Compute the Delta Column
df2['Delta(Hours)'] = (df2['EndDate']-df2['StartDate']).dt.total_seconds()/60/60
# Extract the Date Column
df2['Day'] = (df2['StartDate']).dt.date