function to generate new records based on conditions in a dataframe

Viewed 29

can someone help me, an idea to create a function which evaluates two dates and generates new records with daily breaks:

initial data frame

d = {'name': ['Jack','James'], 'Date_ini': ['2022/01/20 10:10:25','2022/01/22 10:10:25']  ,'Date_end':['2022/01/24 20:24:15','2022/01/22 12:10:25']}
df = pd.DataFrame(d)
df 
name Date_ini Date_end
Jack 2022-01-20 10:10:25 2022-01-24 20:24:15
James 2022-01-22 10:10:25 2022-01-22 12:10:25

I would like to have the following output

name Date_ini Date_end
Jack 2022-01-20 10:10:25 2022-01-20 23:59:59
Jack 2022-01-21 00:00:00 2022-01-21 23:59:59
Jack 2022-01-22 00:00:00 2022-01-22 23:59:59
Jack 2022-01-23 00:00:00 2022-01-23 23:59:59
Jack 2022-01-24 00:00:00 2022-01-24 20:24:15
James 2022-01-22 10:10:25 2022-01-22 12:10:25
0 Answers
Related