I have a dataframe that is like this:
| A | B | C | D |
|---|---|----|---|
| 1 | 3 | 10 | 4 |
| 2 | 3 | 1 | 5 |
| 1 | 7 | 9 | 3 |
Where A B C D are categories, and the values are in the range [1, 10] (some values might not appear in a single column)
I would like to have a dataframe that for every category shows the count of those values. Something like this:
| | A | B | C | D |
|----|---|----|---|---|
| 1 | 2 | 0 | 1 | 0 |
| 2 | 1 | 0 | 0 | 0 |
| 3 | 0 | 2 | 0 | 1 |
| 4 | 0 | 0 | 0 | 1 |
| 5 | 0 | 0 | 0 | 1 |
| 6 | 0 | 0 | 0 | 0 |
| 7 | 0 | 1 | 0 | 0 |
| 8 | 0 | 0 | 0 | 0 |
| 9 | 0 | 0 | 1 | 0 |
| 10 | 0 | 0 | 1 | 0 |
I tried using groupby
and pivot_table
but I can't seem to understand what parameters to give.