i want to split dataframe when value of flag
column change to 1
df=pd.DataFrame({'A':[1,20,40,45,56,1,20,40,45,56],'flag':[3,2,4,1,1,3,3,1,1,1]})
Out[63]:
A flag
0 1 3
1 20 2
2 40 4
3 45 1
4 56 1
5 1 3
6 20 3
7 40 1
8 45 1
9 56 1
desired out:
print(group_1)
A flag
0 1 3
1 20 2
2 40 4
print(group_2)
A flag
0 1 3
1 20 3
CodePudding user response: