I am trying to obtain pairwise counts of two column variables using pandas. I have a dataframe of two columns in the following format:
col1 col2
a   e
b   g
c   h
d   f
a   g
b   h
c   f
d   e
a   f
b   g
c   g
d   h
a   e
b   e
c   g
d   h
b   h
What I would like to get as output would be the following matrix of counts, for e.g.:
  e f g h 
a 2 1 1 0
b 1 0 2 2
c 0 1 2 1
d 1 1 0 2
I am getting totally confused with pandas iterating over columns, rows, indexes and such. Appreciate some guidance here.
 
     
    