Create the output dataframe from input, filter for rows when target == 1 for the first time for each id, or in order words removing consecutive occurrence for each ids where target is 1 however keep all 0s in target before target = 1 and keep group of ids where we don't have 1 e.g a0
Input
df = pd.DataFrame({'ID': ['a0','a0','a0','a1', 'a1', 'a1', 'a1', 'a1', 'a2', 'a2', 'a2', 'a2'],
'date': [ '2019-11-01',
'2019-12-01',
'2020-01-01',
'2019-11-01',
'2019-12-01',
'2020-01-01',
'2020-02-01',
'2020-03-01',
'2019-11-01',
'2019-12-01',
'2020-03-01',
'2020-04-01'],
'target': [0,0,0,0, 0, 1, 1, 0, 0, 1, 0, 1]})
Output
ID date target
a0 2019-11-01 0
a0 2019-12-01 0
a0 2020-01-01 0
a1 2019-11-01 0
a1 2019-12-01 0
a1 2020-01-01 1
a2 2019-11-01 0
a2 2019-12-01 1