I am trying to get frequency counts of certain columns in a dataframe in python. I have a dataframe that looks like this
| Animal | Body Part 1 | Body Part 2 | Body Part 3 |
|---|---|---|---|
| Monkey | Tail | Head | Legs |
| Elephant | Head | Tail | Trunk |
| Monkey | Ears | Head | Legs |
| Elephant | Eyes | Tail | Legs |
The output I am looking for is to get the count of each body part for the corresponding animals (shown below).The values of the different body parts become the rows and the unique animals become the columns, with each cell denoting the count of occurrence of the body part in that animal. It is a form of a pivot table but not sure what is the right method to apply here in python.
| Monkey| Elephant
-------------------------
Tail | 1 | 2
Head | 2 | 1
Legs | 2 | 1
Ears | 1 | 0
Trunk | 0 | 1