-
Notifications
You must be signed in to change notification settings - Fork 0
/
airbnb.py
162 lines (129 loc) · 7.44 KB
/
airbnb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import streamlit as st
from streamlit_option_menu import option_menu
import plotly.express as px
import pandas as pd
import os
from PIL import Image
import warnings
import matplotlib.pyplot as plt
warnings.filterwarnings('ignore')
st.set_page_config(page_title="AirBnb-Analysis", page_icon=":bar_chart:", layout="wide")
st.title(":bar_chart: AirBnb-Analysis")
st.markdown('<style>div.block-container{padding-top:1rem;}</style>', unsafe_allow_html=True)
# with st.headbar:
SELECT = option_menu(
menu_title=None,
options=["Home", "Explore Data", "Contact"],
icons=["house", "bar-chart", "at"],
default_index=2,
orientation="horizontal",
styles={"container": {"padding": "0!important", "background-color": "white", "size": "cover", "width": "100"},
"icon": {"color": "black", "font-size": "20px"},
"nav-link": {"font-size": "20px", "text-align": "center", "margin": "-2px", "--hover-color": "#6F36AD"},
"nav-link-selected": {"background-color": "#6F36AD"}})
#----------------Home----------------------#
if SELECT == "Home":
st.header('Airbnb Analysis')
st.subheader("Airbnb is an American San Francisco-based company operating an online marketplace for short- and long-term homestays and experiences. The company acts as a broker and charges a commission from each booking. The company was founded in 2008 by Brian Chesky, Nathan Blecharczyk, and Joe Gebbia. Airbnb is a shortened version of its original name, AirBedandBreakfast.com. The company is credited with revolutionizing the tourism industry, while also having been the subject of intense criticism by residents of tourism hotspot cities like Barcelona and Venice for enabling an unaffordable increase in home rents, and for a lack of regulation.")
st.subheader('Skills take away From This Project:')
st.subheader('Python Scripting, Data Preprocessing, Visualization, EDA, Streamlit, MongoDb, PowerBI or Tableau')
st.subheader('Domain:')
st.subheader('Travel Industry, Property management and Tourism')
if SELECT == "Explore Data":
fl = st.file_uploader(":file_folder: Upload a file", type=(["csv", "txt", "xlsx", "xls"]))
if fl is not None:
st.write(f"Uploaded file: {fl.name}")
# Check the file extension and read the file accordingly
if fl.name.endswith('.csv'):
df = pd.read_csv(fl, encoding="ISO-8859-1")
elif fl.name.endswith('.txt'):
df = pd.read_csv(fl, delimiter='\t', encoding="ISO-8859-1") # Adjust delimiter if needed
elif fl.name.endswith('.xlsx') or fl.name.endswith('.xls'):
df = pd.read_excel(fl)
else:
st.write("Please Choose A File Above For Visualization")
st.sidebar.header("Choose your filter: ")
# Create for neighbourhood_group
neighbourhood_group = st.sidebar.multiselect("Pick your neighbourhood_group", df["neighbourhood_group"].unique())
if not neighbourhood_group:
df2 = df.copy()
else:
df2 = df[df["neighbourhood_group"].isin(neighbourhood_group)]
# Create for neighbourhood
neighbourhood = st.sidebar.multiselect("Pick the neighbourhood", df2["neighbourhood"].unique())
if not neighbourhood:
df3 = df2.copy()
else:
df3 = df2[df2["neighbourhood"].isin(neighbourhood)]
# Filter the data based on neighbourhood_group, neighbourhood
if not neighbourhood_group and not neighbourhood:
filtered_df = df
elif not neighbourhood:
filtered_df = df[df["neighbourhood_group"].isin(neighbourhood_group)]
elif not neighbourhood_group:
filtered_df = df[df["neighbourhood"].isin(neighbourhood)]
elif neighbourhood:
filtered_df = df3[df["neighbourhood"].isin(neighbourhood)]
elif neighbourhood_group:
filtered_df = df3[df["neighbourhood_group"].isin(neighbourhood_group)]
elif neighbourhood_group and neighbourhood:
filtered_df = df3[df["neighbourhood_group"].isin(neighbourhood_group) & df3["neighbourhood"].isin(neighbourhood)]
else:
filtered_df = df3[df3["neighbourhood_group"].isin(neighbourhood_group) & df3["neighbourhood"].isin(neighbourhood)]
room_type_df = filtered_df.groupby(by=["room_type"], as_index=False)["price"].sum()
col1, col2 = st.columns(2)
with col1:
st.subheader("room_type_ViewData")
fig = px.bar(room_type_df, x="room_type", y="price", text=['${:,.2f}'.format(x) for x in room_type_df["price"]],
template="seaborn")
st.plotly_chart(fig, use_container_width=True, height=200)
with col2:
st.subheader("neighbourhood_group_ViewData")
fig = px.pie(filtered_df, values="price", names="neighbourhood_group", hole=0.5)
fig.update_traces(text=filtered_df["neighbourhood_group"], textposition="outside")
st.plotly_chart(fig, use_container_width=True)
cl1, cl2 = st.columns((2))
with cl1:
with st.expander("room_type wise price"):
st.write(room_type_df.style.background_gradient(cmap="Blues"))
csv = room_type_df.to_csv(index=False).encode('utf-8')
st.download_button("Download Data", data=csv, file_name="room_type.csv", mime="text/csv",
help='Click here to download the data as a CSV file')
with cl2:
with st.expander("neighbourhood_group wise price"):
neighbourhood_group = filtered_df.groupby(by="neighbourhood_group", as_index=False)["price"].sum()
st.write(neighbourhood_group.style.background_gradient(cmap="Oranges"))
csv = neighbourhood_group.to_csv(index=False).encode('utf-8')
st.download_button("Download Data", data=csv, file_name="neighbourhood_group.csv", mime="text/csv",
help='Click here to download the data as a CSV file')
# Create a scatter plot
data1 = px.scatter(filtered_df, x="neighbourhood_group", y="neighbourhood", color="room_type")
data1['layout'].update(title="Room_type in the Neighbourhood and Neighbourhood_Group wise data using Scatter Plot.",
titlefont=dict(size=20), xaxis=dict(title="Neighbourhood_Group", titlefont=dict(size=20)),
yaxis=dict(title="Neighbourhood", titlefont=dict(size=20)))
st.plotly_chart(data1, use_container_width=True)
with st.expander("Detailed Room Availability and Price View Data in the Neighbourhood"):
st.write(filtered_df.iloc[:500, 1:20:2].style.background_gradient(cmap="Oranges"))
# Download orginal DataSet
csv = df.to_csv(index=False).encode('utf-8')
st.download_button('Download Data', data=csv, file_name="Data.csv", mime="text/csv")
import plotly.figure_factory as ff
st.subheader(":point_right: Neighbourhood_group wise Room_type and Minimum stay nights")
with st.expander("Summary_Table"):
df_sample = df[0:5][["neighbourhood_group", "neighbourhood", "reviews_per_month", "room_type", "price", "minimum_nights", "host_name"]]
fig = ff.create_table(df_sample, colorscale="Cividis")
st.plotly_chart(fig, use_container_width=True)
# map function for room_type
# If your DataFrame has columns 'Latitude' and 'Longitude':
st.subheader("Airbnb Analysis in Map view")
df = df.rename(columns={"Latitude": "lat", "Longitude": "lon"})
st.map(df)
col1, col2 = st.columns(2)
# Load and display the image
with col1:
image1 = Image.open("C:/Users/91934/OneDrive/Desktop/Airbnb/image/download.jpeg")
st.image(image1, width=300)
with col2:
col2.subheader("NAME : PRAVEENRAJ S")
col2.subheader("EMAIL: kalpanarajsubu@gmail.com")
col2.subheader("BATCH : dt22")