I have a dataset, df, where I would like to group by one column and then take the count of each category within a second column
name location sku
svc1 ny hey1
svc2 ny hey1
svc3 ny hey1
svc4 ny hey1
lo1 ny ok1
lo2 ny ok1
fab1 ny hi
fab2 ny hi
fab3 ny hi
hello ca no
hello ca no
desired
location sku count
ny hey1 4
ny ok1 2
ny hi 3
ca no 2
doing
df2 = pd.DataFrame()
df2['sku'] = df.groupby('location')['sku'].nth(0)
df2['count'] = df.groupby('sku').count()
However, I am getting NAN for count, and I am not getting all of the data listed under sku.
Any suggestion is appreciated.