How to make a column with grouped value count with respect to its existing columns and conditions on its columns

I have the following data table:

Input:

   Key1    id1-age     id2-age     id3-age    id4-age   id5-age  id1-gender id2-gender   id3-gender    id4-gender    id5-gender 0   a          6          32          61         22       23         M       F               M               F           F 1   b         36          25          52         16       33         M       M               F               F           M 2   c         12          21          45         15       66         F       M               M               M           F 

A single key as multiple age of Individuals, I want make columns which will have counts of age groups for M and agegroup counts for F each row in python

following output is expected:

Expected output

   Key  id1-age id2-age id3-age id4-age id5-age id1-gender  id2-gender  id3-gender  id4-gender  id5-gender  age(2-6)M   age(2-6)F   age(7-11)M  age(7-11)F  age(12-16)M age(12-16)F age(17+)M   age(17+)F 0   a      6      32      61      22      23       M            F            M           F          F          1           0             0         0         0             0           1          3 1   b     36      25      52      16      33       M            M            F           F          M          0           0             0         0         0             1           3          2 2   c     12      21      45      15      66       F            M            M           M          F          0           0             0         1         1             0           2          1 

I want to get the count of male lying in defined age groups and same for female.

I hope the problem statement is clear. Thanks

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.