0

For anyone stumbling across a similar problem, this answered my question: conditional sums for pandas aggregate

I've had success doing a normal groupby on data like this...

score |  type     |
--------------------
1     |  type1    |
3     |  type6    |
5     |  type4    |
3     |  type21   |
2     |  type3    |
4     |  type1    |
...etc...

ideal output

That resulted in something like this...

score |  type     |
--------------------
5     |  882    |
4     |  183    |
3     |  458    |
2     |  1156   |
1     |  10934  |

But I want to be able to take the unique values of the "type" column into account and end up with something more like this...

score | type1 | type 2 | type 3 ... etc.
------------------------------        
5     |   20  |    4   |   ..  |
4     |    3  |    17  |   ..  |
3     |    1  |    12  |   ..  |
2     |   14  |    9   |   ..  |
1     |   70  |    13  |   ..  |

I'm not sure if a groupby is the right approach but I've been banging my head against this and need help.

0 Answers0