I used the below code to filter out the top 5 Items by percentages in the DataFrame
df = df['Country'].value_counts(normalize=True).mul(100).round(2).astype(str) +'%'
df.head(5)
Output
United States 32.78%
India 8.79%
France 4.75%
United Kingdom 4.35%
Germany 3.96%
Name: Country, dtype: object
How can I plot the output using a bar graph?
You need to get your percentages back to a numeric datatype:
df.str[:-1].astype(float).plot.bar()
Output:

import pandas as pd
df = pd.read_clipboard(header=None, sep=r"[ ]{2,}", names=['country', 'percent'])
df['percent'] = df['percent'].astype(str).str.strip('%')
df['percent'] = pd.to_numeric(df['percent'])
df.set_index('country', inplace=True)
df.plot(kind='bar')

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With