'How do I plot top 10 Cities with highest life expectancy rate

I have a dataframe and it has few columns. I want to plot the top 10 countries with highest life expectancy rate. Here is my dataset enter image description here

It should be in matplotlib or seaborn.



Solution 1:[1]

Use DataFrame.nlargest with DataFrame.plot.bar:

(df.nlargest(10, 'Life expectancy(years)(Country)')
   .plot.bar(x='City', y='Life expectancy(years)(Country)'))

For seaborn use seaborn.barplot:

import seaborn as sns
sns.barplot(x='City', 
            y='Life expectancy(years)(Country)',
            data=df.nlargest(10, 'Life expectancy(years)(Country)'))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1