Home > Software design >  Is there a way in pandas to get the count_value of a column and then divide it by the sum of another
Is there a way in pandas to get the count_value of a column and then divide it by the sum of another

Time:11-28

I have a dataframe of matches of League of Legends with the champions played and which team won, and I would like to get a champion count of matches played, and divide it by how many they won to get the win ratio. I can get the amount of times the champions was played with value_count(), but I can't figure out how to sum the result columns depending on the champion played column. The dataframe looks like this. enter image description here

CodePudding user response:

You can check with mean : will return the total win percentage

df.groupby('top')['result'].mean()
  • Related