I am looking to find an efficient way to generate the number of days diff from an initial point in time. The initial point in time the first time (min date) an ID is triggered by the value Y in the Indicator column.
Input
ID Indicator Date
111 Y 1/20/2020
111 N 1/23/2020
111 Y 1/26/2020
111 N 1/26/2020
123 N 1/1/2020
123 Y 1/23/2020
123 Y 2/5/2020
Output
ID Indicator Date Daysdiff
111 Y 1/20/2020 0
111 N 1/23/2020 3
111 Y 1/26/2020 6
111 N 1/26/2020 6
123 N 1/1/2020 -22
123 Y 1/23/2020 0
123 Y 2/5/2020 12
df['Date'] = pd.to_datetime(df['Date'])
df['Daysdiff'] = df.groupby('ID')['Date'].diff().fillna('')
My difficulty is figuring out how to implement the starting point, where day 0 should be when an ID has an Indicator of Y at their earliest point.