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 numpy as np import matplotlib.pyplot as plt df = pd.read_csv('data.csv') df.sort_values('perc_of_5star', inplace=True) df.reset_index(inplace=True) plt.hlines(y=df.decade, xmin=0, xmax=df.perc_of_5star, color='skyblue') plt.gca().invert_yaxis() plt.show()

Questions about programming?Chat with your personal AI assistant