python - How do I create the counts of the column values, grouped by values in the other column in Pandas? -


i have dataframe df has values:

id    status 1       2       b 5       1       3       b 4       b 5       b 

i need group column id column status. issue id can have duplicates, can have same or different codes.

the code have is:

df_new = df.groupby('id').status.nunique() 

however, getting ids grouped, without showing status column , values. need create dataset looks this:

status  count        3   b      4 

you need groupby , count:

df.groupby('status')['status'].count() 

output:

status    3 b    4 name: status, dtype: int64 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -