So I have a Pandas DataFrame with two columns: first is Grade with values 0 to 9 second is Criteria, with values 0 or 1.
Grade (0-9/ Criteria(0/1)
Grade Criteria
0 0 1
1 1 0
2 2 1
3 2 0
4 5 1
5 2 1
etc
I need to count "Criteria rate", which is actually sum of "1"s in Criteria column, divided by appropriate number of rows in Criteria column, but grouped by Grade column values. For example, for Grade = 2 we count sum of 1 in Criteria column and divide it by number of rows with Grade 2: 2/3, so for Grade 2 we get 0.66 approx. In my example, the answer should look like:
Grade / Criteria rate
Grade Criteria
0 0 1.000000
1 1 0.000000
2 2 0.666667
3 5 1.000000
Any ideas, how to do this? Also the add. question - how to do this, if we have "yes/no" text values in Criteria column? I've searched here, but found only solutions to groupby's, divided by total rows count etc.
Thank you!