Generation

generate functionSat, 28 Jan 2023

There is a Pandas dataframe: hotels_rev = df1[['date', 'hotel', 'revenue', 'av_revenue', 'difference', 'in_percent']].sort_values(by=['hotel', 'date']) Construct a bar graph with 'hotel' values in the x axis and change values in the 'date' column and 'av_revenue' values in the y axis

def bar_graph(df): data = df data1 = df[['date', 'revenue']] data2 = data.groupby(['date']).mean() data2['date'] = data2.index data3 = data2.merge(data1, on = 'date') data3 = data3.groupby('hotel', as_index=False).diff() data3['in_percent'] = data3.apply(lambda row: round((row['revenue_x'] / row['revenue_y'] - 1) * 100, 2), axis = 1) data3.head() plt.figure(figsize=(12, 8)) plt.bar(data3['hotel'], data3['in_percent']) plt.xlabel('hotel') plt.ylabel('change in percent') plt.title('change in %') plt.show()

Questions about programming?Chat with your personal AI assistant