Home > Software design >  Plotting barplot category-wise in pandas
Plotting barplot category-wise in pandas

Time:04-05

I have a dataframe containing columns code, year and number_of_dues. I want to plot barplot having year on x axis and no of claims for each year on y axis for each code in one after after subplot fashion. please help me. Sample data is given below.

Code Year   No_of_dues
1     2016   100
1     2017   200
1     2018   300
2     2016   200
2     2017   300
2     2018   500
3     2016   600
3     2017   800
3     2018

CodePudding user response:

Try this one:


    df.groupby(['Code', 'Year'])['No_of_dues'].sum().to_frame().plot.bar()

CodePudding user response:

enter image description here

just use seaborn. set your x and y axes, and hue by the class you want to cohort by

  • Related