I have a dataframe
df = pd.DataFrame({'col1':['a', 'a', 'a', 'b', 'b', 'c', 'c'],
'col2':['a', 'b', 'c', 'b', 'c', 'a', 'c'],
'count':[12, 2, 45, 4, 6, 17, 20]})
col1 col2 count
0 a a 12
1 a b 2
2 a c 45
3 b b 4
4 b c 6
5 c a 17
6 c c 20
and I would like to reshape it so I have a pairwise matrix as below (if there is no row combination of col1
, col2
in the dataframe above the entry should be 0 or else nan. So it would look like that
a b c
a 12 NaN 17.0
b 2 4.0 NaN
c 45 6.0 20.0