I'm trying to count the number of each category of storm for each unique x and y combination. For example. My dataframe looks like:
x y year Category
1 1 1988 3
2 1 1977 1
2 1 1999 2
3 2 1990 4
I want to create a dataframe that looks like:
x y Category 1 Category 2 Category 3 Category 4
1 1 0 0 1 0
2 1 1 1 0 0
3 2 0 0 0 1
I have tried various combinations of .groupby() and .count(), but I am still not getting the desired result. The closet thing I could get is:
df[['x','y','Category']].groupby(['Category']).count()
However, the result counts for all x and y, not the unique pairs:
Cat x y
1 3773 3773
2 1230 1230
3 604 604
4 266 266
5 50 50
NA 27620 27620
TS 16884 16884
Does anyone know how to do a count operation on one column based on the uniqueness of two other columns in a dataframe?