madsryfeldt commited on
Commit
3eef162
1 Parent(s): 65c0104

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -29,19 +29,20 @@ filtered_df = filtered_df[(filtered_df['price'] >= price_range[0]) & (filtered_d
29
  st.write('Below is the sorted and filtered data:')
30
  st.write(filtered_df)
31
 
32
- # Calculate the average price of each available room in each selected neighbourhood
33
  avg_prices = filtered_df.groupby(['neighbourhood', 'room_type'])['price'].mean().reset_index()
34
 
35
- # Plot a histogram of the average prices
36
- if not avg_prices.empty:
37
- st.write('Histogram of Average Price of Each Available Room in Each Neighbourhood:')
 
 
 
38
  fig, ax = plt.subplots()
39
- for room_type in avg_prices['room_type'].unique():
40
- room_prices = avg_prices[avg_prices['room_type'] == room_type]
41
- ax.hist(room_prices['price'], bins=20, alpha=0.5, label=room_type)
42
- ax.legend()
43
- ax.set_xlabel('Average Price')
44
- ax.set_ylabel('Frequency')
45
  st.pyplot(fig)
46
  else:
47
- st.write('No data available for selected filters.')
 
29
  st.write('Below is the sorted and filtered data:')
30
  st.write(filtered_df)
31
 
32
+ # Calculate the average price for each selected neighbourhood
33
  avg_prices = filtered_df.groupby(['neighbourhood', 'room_type'])['price'].mean().reset_index()
34
 
35
+ # Pivot the DataFrame to have neighbourhoods as index and room types as columns
36
+ avg_prices_pivot = avg_prices.pivot(index='neighbourhood', columns='room_type', values='price')
37
+
38
+ # Plot a histogram for each neighbourhood
39
+ if not avg_prices_pivot.empty:
40
+ st.write('Histogram of Average Price for Each Neighbourhood:')
41
  fig, ax = plt.subplots()
42
+ avg_prices_pivot.plot(kind='bar', ax=ax)
43
+ ax.set_xlabel('Neighbourhood')
44
+ ax.set_ylabel('Average Price')
45
+ plt.xticks(rotation=45, ha='right')
 
 
46
  st.pyplot(fig)
47
  else:
48
+ st.write('No data available for selected filters.')