Home > Blockchain >  using pandas groupby apply sum & count for two categorical columns based on another categorical colu
using pandas groupby apply sum & count for two categorical columns based on another categorical colu

Time:10-27

apply pandas groupby or pivot function apply aggregate sum & count for two categorical columns based on another categorical column

enter image description here

output I need

enter image description here

orgainzation_name structure skills

capgemini team_lead python

capgemini manager pmp_certified

capgemini analyst SQL

wipro team_lead python

wipro manager pmp_certified

wipro analyst SQL

infosys team_lead python

infosys manager pmp certifed

infosys analyst SQL

wipro manager pmp_certifed

wipro analyst SQL

wipro analyst SQL

wipro analyst SQL

wipro analyst SQL

capgemini team_lead python

CodePudding user response:

(
df.value_counts(['orgainzation_name','structure','skills'])
    .reset_index()
    .sort_values(['orgainzation_name','structure','skills'],ascending=[True,False,True])
)

enter image description here

You can control the sort order by manipulating ascending=.

  • Related