I am trying to use groupby method for the following problem but can't figure out how to plot a bar graph for new dataframe?

Viewed 34

Display a dataframe of purpose and the total money spent for that particular purpose and plot a bar graph for the same I am given a dataframe with the "purpose" and "money spent" columns I need to plot a bar graph for the new dataframe with total money spent. I have created a new df with the following code but not able to plot the graph with it:

udp1=pd.DataFrame(udp.groupby("PURPOSE")["MONEYSPENT"].sum())
udp1()
1 Answers

just check the documentation.

You can use this, just change the values.

df = pd.DataFrame({'lab':['A', 'B', 'C'], 'val':[10, 30, 20]})
ax = df.plot.bar(x='lab', y='val', rot=0)

enter image description here

There are more examples here and this question with matplotlib

Related