WillacyMe WillacyMe - 1 month ago 6
Python Question

How do you plot a bar graph for given values in a row rather than the number there are in the whole dataframe?

I just need a bar graph showing the

Name
along the x-axis, and for the bars to match up with their
Number
along the y-axis

series = pd.Series(np.arange(5))
df = pd.DataFrame(['Mel','James','Bob','Frank','Julia'], columns=['Name'])
df['Number'] = series

Name Number
0 Mel 5
1 James 6
2 Bob 7
3 Frank 8
4 Julia 9

Answer

Try setting the index

df.set_index('Name').plot.bar()

enter image description here

Comments