I have a pandas dataframe which has results of record similarity. For example, rowid 123 is similar to rowid 512 and rowid 123 is similar to 681. Technically, all three rows are similar. How can I group similar rows?
Note that my data has combinations - Example (123,512) and (512,123)
import pandas as pd
df = pd.DataFrame({'A': [123,123,512,412,412,536], 'B': [512,681,123,536,919,412]})
df
A B
123 512
123 681
512 123
412 536
412 919
536 412
Expected Output
Group1 123
Group1 512
Group1 681
Group2 412
Group2 536
Group2 919
You could use
networkx
to determine connected groups.