madsryfeldt commited on
Commit
fa860a7
1 Parent(s): b3733ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -3,17 +3,14 @@ import streamlit as st
3
  import matplotlib.pyplot as plt
4
 
5
  # Read the CSV file into a Pandas DataFrame
6
- df = pd.read_csv('cph_airbnb_listings.csv')
7
 
8
  # Create a Streamlit app
9
- st.title('AirBnB bookings in Copenhagen')
10
 
11
  # Allow user to add filters for neighbourhoods
12
  selected_neighbourhoods = st.sidebar.multiselect('Select Neighbourhood(s)', df['neighbourhood'].unique())
13
 
14
- # Allow user to add filter for room type
15
- selected_room_type = st.sidebar.selectbox('Select Room Type', ['Private room', 'Entire home/apt'])
16
-
17
  # Allow user to set a price range filter
18
  price_range = st.sidebar.slider('Select Price Range', min_value=0, max_value=1000, step=10, value=(0, 1000))
19
 
@@ -21,15 +18,13 @@ price_range = st.sidebar.slider('Select Price Range', min_value=0, max_value=100
21
  filtered_df = df.copy()
22
  if selected_neighbourhoods:
23
  filtered_df = filtered_df[filtered_df['neighbourhood'].isin(selected_neighbourhoods)]
24
- if selected_room_type:
25
- filtered_df = filtered_df[filtered_df['room_type'] == selected_room_type]
26
  filtered_df = filtered_df[(filtered_df['price'] >= price_range[0]) & (filtered_df['price'] <= price_range[1])]
27
 
28
  # Display the filtered DataFrame
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
 
3
  import matplotlib.pyplot as plt
4
 
5
  # Read the CSV file into a Pandas DataFrame
6
+ df = pd.read_csv('/Users/mads/Desktop/Cand. Merc IM/2. semester/2.4 Digital Innovation/1. Introduction/S1_files/cph_airbnb_listings.csv')
7
 
8
  # Create a Streamlit app
9
+ st.title('Sorted and Filtered Data by Neighbourhood and Price')
10
 
11
  # Allow user to add filters for neighbourhoods
12
  selected_neighbourhoods = st.sidebar.multiselect('Select Neighbourhood(s)', df['neighbourhood'].unique())
13
 
 
 
 
14
  # Allow user to set a price range filter
15
  price_range = st.sidebar.slider('Select Price Range', min_value=0, max_value=1000, step=10, value=(0, 1000))
16
 
 
18
  filtered_df = df.copy()
19
  if selected_neighbourhoods:
20
  filtered_df = filtered_df[filtered_df['neighbourhood'].isin(selected_neighbourhoods)]
 
 
21
  filtered_df = filtered_df[(filtered_df['price'] >= price_range[0]) & (filtered_df['price'] <= price_range[1])]
22
 
23
  # Display the filtered DataFrame
24
  st.write('Below is the sorted and filtered data:')
25
  st.write(filtered_df)
26
 
27
+ # Calculate the average price for each selected neighbourhood and room type
28
  avg_prices = filtered_df.groupby(['neighbourhood', 'room_type'])['price'].mean().reset_index()
29
 
30
  # Pivot the DataFrame to have neighbourhoods as index and room types as columns