Created
April 1, 2021 11:25
-
-
Save kiview/3f8fdf06f0c64dff85496f7e50ba11cc to your computer and use it in GitHub Desktop.
Pandas DataFrame Group by Consecutive Certain Values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from https://towardsdatascience.com/pandas-dataframe-group-by-consecutive-certain-values-a6ed8e5d8cc | |
df_indexed = df.reset_index(drop=True) | |
for k, v in df_indexed[df_indexed['behavior'] == 'not_defined'].groupby((df_indexed['behavior'] != 'not_defined').cumsum()): | |
print(f'[group {k}]') | |
display(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment