I'd like to create an edge list with weights as an attribute (counts number of pair occurrences - e.g., how many months have the pair a-b been together in the same group).
The dataframe contains a monthly snapshot of people in a particular team (there are no duplicates on the monthly groups)
| monthyear | name |
|---|---|
| jun2020 | a |
| jun2020 | b |
| jun2020 | c |
| jul2020 | a |
| jul2020 | b |
| jul2020 | d |
The output should look like the following (it's non-directional so a-b pair is the same as b-a):
| node1 | node2 | weight |
|---|---|---|
| a | b | 2 |
| b | c | 1 |
| a | c | 1 |
| a | d | 1 |
| b | d | 1 |
I managed to create a new dataframe with the names combinations using the following:
df1 = pd.DataFrame(data=list(combinations(df['name'].unique().tolist(), 2)), columns=['node1', 'node2'])
Now I'm not sure how to iterate over this new dataframe to populate the weights. How can this be done?
awhenmonthyear=jun2020.