I have a dataframe like df below. I want to create a new data framework for each piece of data where the condition is true, so this will return df_1, df_2 .... df_n.
| df | | df_1 | | df_2 | | Value | Condition | | Value | | Value | |-------|-----------| |-------|---|-------| | 2 | True | | | 2 | | 0 | | 5 | True | | | 5 | | 5 | | 4 | True | | | 4 | | | | 4 | False | | | | | | | 2 | False | | | | | | | 0 | True | | | | | | | 5 | True | | | | | | | 7 | False | | | | | | | 8 | False | | | | | | | 9 | False | | | | | |
My only idea is to skip the data frame by returning a start and end index for each piece of True values, and then creating new dataframes with a loop going through the returned indexes, returning something like this for each start / end pair:
newdf = df.iloc[start:end]
But doing it seems ineffective.
source share