How to group and display a 2 column frame in python

I have a dataset with two columns: "Views" and "Year". I have already subdivided the data so that in the dataset below it contains only one blue whale species:

Species  Year
1      Blue Whale  1920
2      Blue Whale  1920
3      Blue Whale  1920
5      Blue Whale  1920
6      Blue Whale  1920
7      Blue Whale  1920
16     Blue Whale  1920
17     Blue Whale  1922
18     Blue Whale  1922
19     Blue Whale  1922
20     Blue Whale  1922
21     Blue Whale  1922
22     Blue Whale  1922
23     Blue Whale  1922
24     Blue Whale  1922
25     Blue Whale  1922
26     Blue Whale  1922
28     Blue Whale  1924
29     Blue Whale  1924
30     Blue Whale  1924

      

In this case, how do I plot the year as the x and y axis as the whale watching count for this year?

+3


source to share


2 answers


Use groupby

and count

:

df.groupby('Year').count().plot(kind='bar')

      



enter image description here

0


source


You can use value_counts

with Series.plot.bar

:

df['Year'].value_counts().plot.bar()

      



graph

+3


source







All Articles