I have dataframe contains ACQ/REL pair recusively as below:
import pandas as pd
data = [
[ 2023-06-05 16:51:27.561 , ACQ , location ],
[ 2023-06-05 16:51:27.564 , ACQ , location ],
[ 2023-06-05 16:51:27.567 , ACQ , location ],
[ 2023-06-05 16:51:27.571 , REL , location ],
[ 2023-06-05 16:51:27.573 , REL , location ],
[ 2023-06-05 16:51:27.587 , REL , location ],
[ 2023-06-05 16:51:28.559 , ACQ , location ],
[ 2023-06-05 16:51:28.561 , ACQ , location ],
[ 2023-06-05 16:51:28.563 , ACQ , location ],
[ 2023-06-05 16:51:28.566 , REL , location ],
[ 2023-06-05 16:51:28.569 , REL , location ],
[ 2023-06-05 16:51:28.575 , REL , location ]
]
df = pd.DataFrame(data,columns=[ ts , action , name ])
I would re-orgnize it by ACQ/REL pairs, the outer ACQ/REL pairs as a group, so that the output dataframe looks like below:
0 2023-06-05 16:51:27.561 ACQ location
5 2023-06-05 16:51:27.587 REL location
1 2023-06-05 16:51:27.564 ACQ location
4 2023-06-05 16:51:27.573 REL location
2 2023-06-05 16:51:27.567 ACQ location
3 2023-06-05 16:51:27.571 REL location
6 2023-06-05 16:51:28.559 ACQ location
11 2023-06-05 16:51:28.575 REL location
7 2023-06-05 16:51:28.561 ACQ location
10 2023-06-05 16:51:28.569 REL location
8 2023-06-05 16:51:28.563 ACQ location
9 2023-06-05 16:51:28.566 REL location
Current example is 3 pairs a group but it s not constantly the same. What s proper way to get such results?