Problem
I have the following Pandas dataframe:
data = {
'ID': [100, 100, 100, 100, 200, 200, 200, 200, 200, 300, 300, 300, 300, 300],
'value': [False, False, True, False, False, True, True, True, False, False, False, True, True, False],
}
df = pandas.DataFrame (data, columns = ['ID','value'])
I want to get the following groups:
- Group 1: for each ID, all False rows until the first True row of that ID
- Group 2: for each ID, all False rows after the last True row of that ID
- Group 3: all true rows
Can this be done with pandas?
What I've tried
I've tried
group = df.groupby((df['value'].shift() != df['value']).cumsum())
but this returns an incorrect result.