Here's another great question on dataframes asked in the r that would benefit from a pandas solution. Here's the question.
I want to count per
country
the number of times thestatus
isopen
and the number of times thestatus
isclosed
. Then calculate thecloserate
percountry
.Data:
customer country closeday status 1 1 BE 2017-08-23 closed 2 2 NL 2017-08-05 open 3 3 NL 2017-08-22 closed 4 4 NL 2017-08-26 closed 5 5 BE 2017-08-25 closed 6 6 NL 2017-08-13 open 7 7 BE 2017-08-30 closed 8 8 BE 2017-08-05 open 9 9 NL 2017-08-23 closed
The idea is to get an output depicting the number of
open
andclosed
status, and theclose_ratio
. This is the desired output:country closed open closed_ratio BE 3 1 0.75 NL 3 2 0.60
Look forward to your suggestions.
Solution included below in an answer. Welcome other solutions.