Python Forum
Not able to figure out how to create bar plot on aggregate data - Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not able to figure out how to create bar plot on aggregate data - Python
#1
Hello,

I have been trying to use a series that I have got using aggregate function and plot a bar plot but not able to get it. I have quickly got the correct aggregate function, but not able to identify how to get x and y axis for plotting bar plot.

DataFrame is fab1:
indicator has only 0 and 1 values
Objective - **to get a bar plot**
x axis :- periods (1,2,3,4)
y axis :- counts of 0 and 1 for each of the periods. So, a total of 8 bar lines should come

Aggregate function used by me and result:

    c1=fab1.groupby(['period','indicator'])['indicator'].count()
    c1
Result is:this one is the correct result. Third column is the count of 0 and 1 for a specific period (column 1). How to build the bar plot/histogram?

Output:
period indicator 1 0 61 1 19 2 0 68 1 14 3 0 64 1 18 4 0 53 1 27 Name: indicator, dtype: int64
Now I want to use use the bar plot function to complete my objective, getting stuck. please help me

Raw dataset- few rows

period indicator

0 1 0

1 1 0

2 1 0

3 1 0

4 1 0

5 1 0

6 1 0

7 1 0

8 1 0

9 1 0
.... around 350 observations

just to add that below code gives me output, but how to make customised bar plot.
fab1.groupby(['period','indicator'])['indicator'].count().plot(kind='bar')
Reply
#2
Suggest using matplotlib. It is probably the most common python graphing library. The part on histograms is here. You organize your data into bins and then plot the histogram.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  1D plot frome 3D data layla 7 1,099 Jul-16-2023, 10:51 PM
Last Post: Pedroski55
  How to create a plot with line graphs and vertical bars devansing 6 2,254 Feb-28-2023, 05:38 PM
Last Post: devansing
  How to plot 2 graphs in one figure? man0s 1 1,336 Apr-25-2022, 09:18 AM
Last Post: Axel_Erfurt
  extract and plot data from a txt file usercat123 2 1,208 Apr-20-2022, 06:50 PM
Last Post: usercat123
  Searching Module to plot large data G_rizzle 0 1,422 Dec-06-2021, 08:00 AM
Last Post: G_rizzle
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,245 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  average aggregate function winya 3 2,591 Apr-20-2020, 03:21 AM
Last Post: scidam
  How to create correct scatter plot for PCA? LK91 0 2,069 Dec-11-2019, 07:53 PM
Last Post: LK91
  Sample based on the distribution of a feature to create more balanced data set dervast 1 1,735 Nov-15-2019, 12:25 AM
Last Post: schuler
  It doesn't show scatter plot but it says: "<Figure size 640x480 with 1 Axes>" dcardonaa 0 3,457 Oct-10-2019, 02:34 AM
Last Post: dcardonaa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020