Spaces:
Runtime error
Runtime error
Commit
•
3eef162
1
Parent(s):
65c0104
Update app.py
Browse files
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
|
33 |
avg_prices = filtered_df.groupby(['neighbourhood', 'room_type'])['price'].mean().reset_index()
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
38 |
fig, ax = plt.subplots()
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
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.')
|