I'm a bit new to this so please be gentle. I have a dataframe structured like the table below and I'd like to groupby column "P" and make new columns for the distinct/unique values in column "U" and then count the instances of those values.
P | U |
---|---|
p1 | u1 |
p1 | u1 |
p1 | u3 |
p2 | u1 |
p2 | u2 |
p2 | u3 |
Essentially I'd like the output to look like this.
P | u1 | u2 | u3 |
---|---|---|---|
p1 | 2 | 0 | 1 |
p2 | 1 | 1 | 1 |
I guess I'm not sure how to articulate what it is I'm trying to do or what the terminology is to do a Google search to figure out myself, so perhaps someone can describe the pandas/python method that's best used for what I'm looking for I could look up examples myself. Thanks!