Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- Week_1_project_visualization.py +54 -0
- app.py +54 -0
Week_1_project_visualization.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import plotly.express as px
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
# Display title and text
|
6 |
+
st.title("Week 1 - Data and visualization")
|
7 |
+
st.markdown("Here we can see the dataframe we've created during this weeks project.")
|
8 |
+
|
9 |
+
# Read dataframe
|
10 |
+
dataframe = pd.read_csv(
|
11 |
+
"WK1_Airbnb_Amsterdam_listings_proj_solution.csv",
|
12 |
+
names=[
|
13 |
+
"Airbnb Listing ID",
|
14 |
+
"Price",
|
15 |
+
"Latitude",
|
16 |
+
"Longitude",
|
17 |
+
"Meters from chosen location",
|
18 |
+
"Location",
|
19 |
+
],
|
20 |
+
)
|
21 |
+
|
22 |
+
# We have a limited budget, therefore we would like to exclude
|
23 |
+
# listings with a price above 100 pounds per night
|
24 |
+
dataframe = dataframe[dataframe["Price"] <= 100]
|
25 |
+
|
26 |
+
# Display as integer
|
27 |
+
dataframe["Airbnb Listing ID"] = dataframe["Airbnb Listing ID"].astype(int)
|
28 |
+
# Round of values
|
29 |
+
dataframe["Price"] = "£ " + dataframe["Price"].round(2).astype(str)
|
30 |
+
# Rename the number to a string
|
31 |
+
dataframe["Location"] = dataframe["Location"].replace(
|
32 |
+
{1.0: "To visit", 0.0: "Airbnb listing"}
|
33 |
+
)
|
34 |
+
|
35 |
+
# Display dataframe and text
|
36 |
+
st.dataframe(dataframe)
|
37 |
+
st.markdown("Below is a map showing all the Airbnb listings with a red dot and the location we've chosen with a blue dot.")
|
38 |
+
|
39 |
+
# Create the plotly express figure
|
40 |
+
fig = px.scatter_mapbox(
|
41 |
+
lat=dataframe["Latitude"],
|
42 |
+
lon=dataframe["Longitude"],
|
43 |
+
color=dataframe["Location"],
|
44 |
+
zoom=11,
|
45 |
+
height=500,
|
46 |
+
width=800,
|
47 |
+
hover_name=dataframe["Price"],
|
48 |
+
labels={"color": "Locations"},
|
49 |
+
)
|
50 |
+
fig.update_geos(center=dict(lat=dataframe.iloc[0][2], lon=dataframe.iloc[0][3]))
|
51 |
+
fig.update_layout(mapbox_style="stamen-terrain")
|
52 |
+
|
53 |
+
# Show the figure
|
54 |
+
st.plotly_chart(fig, use_container_width=True)
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import plotly.express as px
|
3 |
+
import streamlit as st
|
4 |
+
|
5 |
+
# Display title and text
|
6 |
+
st.title("Week 1 - Data and visualization")
|
7 |
+
st.markdown("Here we can see the dataframe we've created during this weeks project.")
|
8 |
+
|
9 |
+
# Read dataframe
|
10 |
+
dataframe = pd.read_csv(
|
11 |
+
"WK1_Airbnb_Amsterdam_listings_proj_solution.csv",
|
12 |
+
names=[
|
13 |
+
"Airbnb Listing ID",
|
14 |
+
"Price",
|
15 |
+
"Latitude",
|
16 |
+
"Longitude",
|
17 |
+
"Meters from chosen location",
|
18 |
+
"Location",
|
19 |
+
],
|
20 |
+
)
|
21 |
+
|
22 |
+
# We have a limited budget, therefore we would like to exclude
|
23 |
+
# listings with a price above 100 pounds per night
|
24 |
+
dataframe = dataframe[dataframe["Price"] <= 100]
|
25 |
+
|
26 |
+
# Display as integer
|
27 |
+
dataframe["Airbnb Listing ID"] = dataframe["Airbnb Listing ID"].astype(int)
|
28 |
+
# Round of values
|
29 |
+
dataframe["Price"] = "£ " + dataframe["Price"].round(2).astype(str)
|
30 |
+
# Rename the number to a string
|
31 |
+
dataframe["Location"] = dataframe["Location"].replace(
|
32 |
+
{1.0: "To visit", 0.0: "Airbnb listing"}
|
33 |
+
)
|
34 |
+
|
35 |
+
# Display dataframe and text
|
36 |
+
st.dataframe(dataframe)
|
37 |
+
st.markdown("Below is a map showing all the Airbnb listings with a red dot and the location we've chosen with a blue dot.")
|
38 |
+
|
39 |
+
# Create the plotly express figure
|
40 |
+
fig = px.scatter_mapbox(
|
41 |
+
lat=dataframe["Latitude"],
|
42 |
+
lon=dataframe["Longitude"],
|
43 |
+
color=dataframe["Location"],
|
44 |
+
zoom=11,
|
45 |
+
height=500,
|
46 |
+
width=800,
|
47 |
+
hover_name=dataframe["Price"],
|
48 |
+
labels={"color": "Locations"},
|
49 |
+
)
|
50 |
+
fig.update_geos(center=dict(lat=dataframe.iloc[0][2], lon=dataframe.iloc[0][3]))
|
51 |
+
fig.update_layout(mapbox_style="stamen-terrain")
|
52 |
+
|
53 |
+
# Show the figure
|
54 |
+
st.plotly_chart(fig, use_container_width=True)
|