首页 > 解决方案 > How to get Adjacency Matrix or pairs from two columns(key, value)?

问题描述

I got a dataframe with two columns(key, value)

key,value 
1,A
1,B
2,B
2,C

how to get an adjacency matrix or adjacency pairs(connect values if they have the same key), something like

  A B C
A 0,1,0
B 1,0,1
C 0,1,0

I tried pandas.crosstab, which works fine on small data, but got memory error on a big dataframe(3,000,000 rows, 500,000 distinct value). Any help would be appreciated.

标签: pythonpandasapache-sparkgraph

解决方案


推荐阅读