In R, I can create a network based on two columns of a dataframe and then assign its cluster membership ids as a new aggregated column to the original dataframe as shown below.
library(igraph)
library(data.table)
g = graph_from_data_frame(df[, .(col1, col2)])
clu = clusters(g)
df[, cluId := clu$membership[as.character(df[, col1])]]
How would you do the same operation in Python with pandas and igraph, or networkx? I found a similar question here but the answer provided is very slow.
Assigning Group ID to components in networkx
example:
