Generation

generate functionThu, 19 Jan 2023

There is a Pandas dataframe: place decade perc_of_5star 0 1 2010-2020 2.300 1 2 1900-1910 1.379 2 3 1970-1980 1.179 3 4 2000-2010 1.176 4 5 1960-1970 1.133 build a horizontal barchart with perc_of_5star columns in descending order and decade values on the y-axis

import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame( {'place': [1, 2, 3, 4, 5], 'decade': ['2010-2020', '1900-1910', '1970-1980', '2000-2010', '1960-1970'], 'perc_of_5star': [2.3, 1.379, 1.179, 1.176, 1.133]}) df.sort_values(by='perc_of_5star', ascending=True).plot(kind='barh', x='decade', y='perc_of_5star', legend=False) plt.show()

Questions about programming?Chat with your personal AI assistant