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 import numpy as np df = pd.DataFrame({'place': [1, 2, 3, 4, 5], 'decade': ['2010-2020','1900-1910','1970-1980','2000-2010','1960-1970'], 'perc_of_5star': [2.300, 1.379, 1.179, 1.176, 1.133]}) plt.barh(df['decade'], df['perc_of_5star']) plt.xlabel('Percentage of 5 star reviews') plt.ylabel('Decades') plt.title('Percentage of 5 star reviews by decade') plt.show()

Questions about programming?Chat with your personal AI assistant