I have struggles when trying to group a dataframe based on the matches of its values, let's say:
print(crosstabsdf1)
Index Area Area_2
0 188 181
1 190 188
2 192 190
3 115 110
4 138 121
... ... ...
2510 173 174
2511 177 178
2512 174 175
2513 176 177
2604 181 182
[361 rows x 2 columns]
When I seek for the matches of a value, for instance:
crosstabsdf1[crosstabsdf1['Area']==181]
Index Area Area_2
9 181 175
260 181 182
crosstabsdf1[crosstabsdf1['Area_2']==181]
Index Area Area_2
0 188 181
157 180 181
So, I would like to seek for grouping all of the matches between each pair (by match I mean, that, when I have a row:
Area Area_2
181 175
181 182
188 181
180 181
it means that the areas 181 and 175, and 181-182, and so on, are adjacent),
So, is there a pandas way (or maybe a defined function) to group each Area and display it into many rows depending on its ocurrances of adjacency with other areas, like this:
Index Area Area_2
0 181 175
1 181 180
2 181 182
3 181 188
Thank you