I am attempting to take a 2 column pandas df (where column 1 is node 1, and column 2 is node 2, thus signifying an edge between the nodes) and converting to adjacency matrix. I have followed the following code snippet from SO (Create adjacency matrix for two columns in pandas dataframe), but this does not create a symmetric matrix, which is what I need. It still makes correct dimension, but help would be greatly appreciated:
Data: 2 column df of edges
Code:
df = pd.crosstab(edges_df[0], edges_df[1])
idx = df.columns.union(df.index)
df = df.reindex(index = idx, columns=idx, fill_value=0)