How to plot frequency count of pandas column

Viewed 28682

I have a pandas dataframe like this:

    Year   Winner
4   1954  Germany
9   1974  Germany
13  1990  Germany
19  2014  Germany
5   1958   Brazil
6   1962   Brazil
8   1970   Brazil
14  1994   Brazil
16  2002   Brazil

How to plot the frequency count of column Winner, so that y axis has frequency and x-axis has name of country?

I tried:

import numpy as np
import pandas as pd

df.groupby('Winner').size().plot.hist()
df1['Winner'].value_counts().plot.hist()
3 Answers

You are close, need Series.plot.bar because value_counts already count frequency:

df1['Winner'].value_counts().plot.bar()

g

Also working:

df1.groupby('Winner').size().plot.bar()

Difference between solutions is output of value_counts will be in descending order so that the first element is the most frequently-occurring element.

In addition to @jezrael's answer, you can also do:

df1['Winner'].value_counts().plot(kind='bar')

Other one from @jezrael could be:

df1.groupby('Winner').size().plot(kind='bar')

Just want to say this works with the latest version of plotly. Just need to add ,text_auto=True. Example: px.histogram(df, x="User Country",text_auto=True)

Related