I have a pandas dataframe df which has n rows and n columns. Each row is an author and each column is the same author. The values in the data frame represent the number of times each author 'r' from row r has co-authored a paper with author 'c' from column c.
How can I melt this data.frame into long-format?
input
Alice John Foo Jill
Alice 0. 4. 3. 1
John 4. 0. 3. 3
Foo 4. 3. 0. 4
Jill. 1. 3. 4. 0.
output
Source Target Value
Alice Alice 0
Alice John 4
Alice Foo 3
Alice Bar 5
Alice Jill 1
John Alice 4
John Bar 0
John Foo 3
John Jill 3
John John 0
.....