Bottom Page

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')
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  average aggregate function winya 3 287 Apr-20-2020, 03:21 AM
Last Post: scidam
  How to create correct scatter plot for PCA? LK91 0 190 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 300 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 477 Oct-10-2019, 02:34 AM
Last Post: dcardonaa
  HeatMap plot with arduino serial data tshivam 0 934 Oct-08-2018, 10:57 AM
Last Post: tshivam
  How to plot data to the same figure for every run? chry5ler 3 982 Aug-03-2018, 04:21 PM
Last Post: heras

Forum Jump:


Users browsing this thread: 1 Guest(s)