I have a table that looks like this:
| Celebrity | Username |
|---|---|
| A | user1 |
| B | user1 |
| C | user2 |
| A | user3 |
| A | user2 |
| D | user2 |
| D | user3 |
I wrote a function to find the overlaps of users between two celebrities:
def num_of_fans_overlap(cel1,cel2,data,Celebrity,Usernames):
l = [cel1,cel2]
Res = len(data.loc[data['Usernames'].map(data.groupby('Usernames').agg(set)['Celebrity'].eq(set(l)))])/2
return print(int(Res))
for example, if I run num_of_fans_overlap(A,B,data,"Celebrity","Username"), I will get 1, which means one user has followed both celebrities.
Now I want to run a for loop, and the output should look like this:
("A", "B", 1)
("A", "C", 1)
("A", "D", 2)
("B", "C", 0)
("B", "D", 0)
("C", "D", 1)
I have been stuck here. Hope someone can help.