I have a dataframe like this:
match team1 team2 winner
1 MI KKR MI
2 DD CSK DD
3 RCB DC RCB.....
What I wanted to calculate is how many times has a team won against another team in the tournament. Like for MI vs KKR:
MI:10
KKR:5
So I have written a function like this:
def comparator(team1):
mt1=matches[((matches['team1']==team1)|(matches['team2']==team1))]
teams=['MI','KKR','RCB','DC','CSK','RR','DD','GL','KXIP','SRH','RPS','KTK','PW']
teams.remove(team1)
opponents=teams.copy()
for i in opponents:
mt2=mt1[(((mt1['team1']==i)|(mt1['team2']==i)))&((mt1['team1']==team1)|(mt1['team2']==team1))].winner.value_counts()
print(mt2)
comparator('MI')
Now in the function, the mt2 prints out the correct values for the respective wins for team1 and team2. The output is like this:
MI 13
KKR 5
Name: winner, dtype: int64
MI 11
RCB 8
Name: winner, dtype: int64
Now the output is correct but the format is not appropriate. I want to convert the following output into a dataframe.
I tried appending the the values into a list but it is not working as the lines Name: winner, dtype: int64 is also getting appended into the list.
How do I convert it into a dataframe?
to_frame()on the result