Issue
I have a pandas dataframe (called result
), which looks something like this:
event_1 | event_2 | event_3 |
---|---|---|
1 | 1 | 1 |
1 | 1 | 1 |
1 | Del | 1 |
1 | 1 | 1 |
And I would like to remove all the rows before the one in which there is the value Del
. So that the result would look like this:
event_1 | event_2 | event_3 |
---|---|---|
1 | Del | 1 |
1 | 1 | 1 |
I tried adapting some code I found in some other posts, but it doesn't seem to do the trick (it actually runs for a lot, and never stops to run).
result.groupby('event_1').apply(lambda x: x.loc[(x.event_2 == "Del").idxmax():,:]).reset_index(drop=True)
Solution
You can use boolean slicing:
df[df['event_2'].eq('Del').cummax()]
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.