1

I'm trying to plot multiple columns onto a single bar chart.

First, I defined them:

public_action_sum = df['Q17.4_1'].sum()    
testified_sum = df['Q17.4_4'].sum()
met_el_sum = df['Q17.4_5'].sum()
... 

and then merged those sums into a single dataframe: actions_combined = [public_action_sum, testified_sum, met_el_sum, policy_sum, bill_sum]

I'm trying to use pandas.DataFrame.plot.bar and have written:

pd.DataFrame.plot.bar(x['Q17.4_1','Q17.4_4','Q17.4_5','Q17.4_6','Q17.4_7'],y=actions_combined,rot=0)

but am getting the error "missing 1 required positional argument: 'self'

I've spent the last hour and a half trying to figure this iout, and am not sure where I'm going wrong. Thoughts? THANKS!

aks85
  • 695
  • 3
  • 11
  • 24
  • You can see my answer below, but you are also missing an equals sign `=` when you are assigning keyword `x` in your code above. – rahlf23 Sep 26 '18 at 23:35

1 Answers1

2

Here is a short example dataframe:

         Date     Open     High     Low    Close  Adj Close    Volume
0  1996-01-01  4.06250  4.12500  3.8750  3.90625   3.093209   7048800
1  1996-02-01  3.84375  3.96875  3.5000  3.62500   2.870497  12864000
2  1996-03-01  3.50000  4.25000  3.5000  4.12500   3.266428   9526400
3  1996-04-01  4.06250  4.68750  4.0625  4.50000   3.563378   5693600
4  1996-05-01  4.40625  4.65625  4.1250  4.21875   3.340666  30480000

Then you can do:

import pandas as pd
import matplotlib.pyplot as plt

df[['Open','High','Low','Close','Adj Close']].plot(kind='bar')

plt.show()

Which gives:

enter image description here

rahlf23
  • 8,869
  • 4
  • 24
  • 54