Jrblack
Jrblack

Reputation: 39

Is there a way in pandas to get the count_value of a column and then divide it by the sum of another column?

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

Upvotes: 0

Views: 110

Answers (1)

BENY
BENY

Reputation: 323226

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

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

Upvotes: 1

Related Questions