Spaces:
Sleeping
Sleeping
Chitranshu
commited on
Commit
•
3aa78d9
1
Parent(s):
e44850f
Update app.py
Browse files
app.py
CHANGED
@@ -1,305 +1,194 @@
|
|
1 |
import pandas as pd
|
2 |
-
import pandas as pd
|
3 |
import panel as pn
|
4 |
import hvplot.pandas
|
5 |
-
|
6 |
-
from
|
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 |
-
color='#E10F14',
|
67 |
-
title='Best Food Truck in Mumbai: Price vs. Name',
|
68 |
-
xlabel='Food Truck Name',
|
69 |
-
ylabel='Price',
|
70 |
-
hover_cols=['RATING', 'REGION', 'CUSINE_CATEGORY'],
|
71 |
-
rot=90,
|
72 |
-
width=900,
|
73 |
-
height=500
|
74 |
-
)
|
75 |
|
76 |
-
#
|
77 |
-
|
78 |
|
79 |
-
#
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
-
|
83 |
-
top_seafood_df = seafood_df.sort_values(by='RATING', ascending=False).head(10)
|
84 |
|
85 |
-
# Create the
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
color='#E10F14',
|
90 |
-
title='Top 10 Seafood Restaurants in Mumbai: Price vs. Name',
|
91 |
-
xlabel='Restaurant Name',
|
92 |
-
ylabel='Price',
|
93 |
-
hover_cols=['RATING', 'REGION', 'CUSINE_CATEGORY'],
|
94 |
-
rot=90,
|
95 |
-
width=900,
|
96 |
-
height=500
|
97 |
-
)
|
98 |
|
99 |
-
#
|
100 |
-
|
101 |
|
102 |
# Define Panel widgets
|
103 |
yaxis_radio = pn.widgets.RadioButtonGroup(
|
104 |
name='Y axis',
|
105 |
-
options=['
|
106 |
-
button_type='
|
107 |
-
|
108 |
-
|
109 |
)
|
110 |
|
111 |
# Define the Panel layout
|
112 |
panel_layout = pn.Column(
|
113 |
-
|
|
|
114 |
)
|
115 |
|
116 |
-
# Create the map centered at Mumbai with dark mode
|
117 |
-
mumbai_map = folium.Map(location=[19.0760, 72.8777], zoom_start=12, tiles="StamenTonerBackground")
|
118 |
-
|
119 |
-
# Add a marker for Mumbai
|
120 |
-
folium.Marker(
|
121 |
-
location=[19.0760, 72.8777],
|
122 |
-
popup='<b>Mumbai</b>',
|
123 |
-
icon=folium.Icon(color='red', icon_color='white', icon='heart', prefix='fa')
|
124 |
-
).add_to(mumbai_map)
|
125 |
-
|
126 |
-
# Add markers for the specified locations
|
127 |
-
locations = [
|
128 |
-
{'name': 'Hitchki', 'region': 'Bandra', 'rating': '4.8', 'latitude': 19.0590, 'longitude': 72.8292, 'cuisine': 'Indian'},
|
129 |
-
{'name': 'Downtown China', 'region': 'Andheri', 'rating': '4.9', 'latitude': 19.1136, 'longitude': 72.8697, 'cuisine': 'Chinese'},
|
130 |
-
{'name': 'The Northern Vibe', 'region': 'Powai', 'rating': '4.7', 'latitude': 19.1187, 'longitude': 72.9073, 'cuisine': 'Continental'},
|
131 |
-
{'name': 'Rajdhani', 'region': 'Ghatkopar', 'rating': '4.8', 'latitude': 19.0866, 'longitude': 72.9081, 'cuisine': 'Indian'},
|
132 |
-
{'name': 'Trumpet Sky Lounge', 'region': 'Andheri', 'rating': '4.9', 'latitude': 19.1189, 'longitude': 72.8537, 'cuisine': 'International'},
|
133 |
-
{'name': 'Dessertino', 'region': 'Kandivali', 'rating': '4.7', 'latitude': 19.2128, 'longitude': 72.8376, 'cuisine': 'Desserts'}
|
134 |
-
]
|
135 |
-
|
136 |
-
for location in locations:
|
137 |
-
popup_content = f"<b>Name:</b> {location['name']}<br><b>Region:</b> {location['region']}<br><b>Rating:</b> {location['rating']}<br><b>Cuisine:</b> {location['cuisine']}"
|
138 |
-
if location['name'] == 'Dessertino':
|
139 |
-
icon = folium.Icon(color='red', icon_color='white', icon='coffee', prefix='fa')
|
140 |
-
else:
|
141 |
-
icon = folium.Icon(color='red', icon_color='white', icon='cutlery', prefix='fa')
|
142 |
-
folium.Marker(
|
143 |
-
location=[location['latitude'], location['longitude']],
|
144 |
-
popup=popup_content,
|
145 |
-
icon=icon
|
146 |
-
).add_to(mumbai_map)
|
147 |
-
|
148 |
-
title_html = """
|
149 |
-
<div style="font-size: 17px; font-weight: bold; text-align: left;">The best Restaurant to order food with best price and Quality</div>
|
150 |
-
"""
|
151 |
-
# Wrap the map in a Panel object
|
152 |
-
panel_map = pn.pane.HTML(title_html + mumbai_map._repr_html_(), width=800, height=600)
|
153 |
-
|
154 |
# Define the callback function for the radio button
|
155 |
def update_chart(event):
|
156 |
-
if event.new == '
|
157 |
-
panel_layout[1
|
158 |
-
elif event.new == '
|
159 |
-
panel_layout[1
|
160 |
-
elif event.new == '
|
161 |
-
panel_layout[1
|
162 |
-
elif event.new == '
|
163 |
-
panel_layout[1
|
164 |
-
elif event.new == '
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
# Create the bar plot using hvplot
|
169 |
-
bar_plot_highest_rated = highest_rated.hvplot.bar(
|
170 |
-
x='NAME',
|
171 |
-
y='PRICE',
|
172 |
-
color='#E10F14',
|
173 |
-
title='Highest Rated Restaurants in Mumbai: Price vs. Name',
|
174 |
-
xlabel='Restaurant Name',
|
175 |
-
ylabel='Price',
|
176 |
-
hover_cols=['RATING', 'REGION', 'CUSINE_CATEGORY'],
|
177 |
-
rot=90,
|
178 |
-
width=900,
|
179 |
-
height=500
|
180 |
-
)
|
181 |
-
|
182 |
-
# Wrap the bar plot in a Panel object
|
183 |
-
panel_highest_rated = pn.panel(bar_plot_highest_rated)
|
184 |
-
panel_layout[1:] = [panel_highest_rated]
|
185 |
-
elif event.new == 'Top Avg Price':
|
186 |
-
# Filter the DataFrame for ratings greater than or equal to 4.5
|
187 |
-
filtered_df = zomato_df[zomato_df['RATING'] >= 4.5]
|
188 |
-
|
189 |
-
# Calculate the mean price for each combination of 'REGION' and 'CUSINE TYPE'
|
190 |
-
highest_rated_price_df = filtered_df.groupby(['REGION', 'CUSINE TYPE'])['PRICE'].mean().reset_index()
|
191 |
-
|
192 |
-
# Sort the DataFrame by 'REGION' in alphabetical order
|
193 |
-
highest_rated_price_df = highest_rated_price_df.sort_values('REGION')
|
194 |
-
|
195 |
-
# Create a scatter plot with rotated labels and star marker
|
196 |
-
scatter_plot_top_avg_price = highest_rated_price_df.hvplot.scatter(
|
197 |
-
x='REGION',
|
198 |
-
y='PRICE',
|
199 |
-
c='CUSINE TYPE',
|
200 |
-
cmap='Category10',
|
201 |
-
title='Avg Price Distribution of High-rated restaurants for each Cuisine Type',
|
202 |
-
size=100, # Increase the marker size
|
203 |
-
rot=90,
|
204 |
-
width=900,
|
205 |
-
height=500,
|
206 |
-
marker='*',
|
207 |
-
)
|
208 |
-
|
209 |
-
# Create a Panel object with the scatter plot
|
210 |
-
panel_top_avg_price = pn.panel(scatter_plot_top_avg_price)
|
211 |
-
panel_layout[1:] = [panel_top_avg_price]
|
212 |
-
elif event.new == 'Chinese Resto':
|
213 |
-
zomato_df_cleaned = zomato_df.dropna(subset=['CUSINE_CATEGORY'])
|
214 |
-
chinese_df = zomato_df_cleaned[zomato_df_cleaned['CUSINE_CATEGORY'].str.contains('Chinese')]
|
215 |
-
chinese_rest_df = chinese_df.groupby(by='REGION').agg({'NAME': 'count', 'PRICE': 'mean'}).rename(columns={'NAME': 'COUNT OF RESTAURANTS'}).reset_index()
|
216 |
-
chinese_rest_df = chinese_rest_df.sort_values('COUNT OF RESTAURANTS', ascending=False).head(25)
|
217 |
-
bar_plot = chinese_rest_df.hvplot.bar(
|
218 |
-
x='REGION',
|
219 |
-
y='COUNT OF RESTAURANTS',
|
220 |
-
color='#E10F14', # Set the color to red
|
221 |
-
title='No. of Chinese Restaurants by Places',
|
222 |
-
xlabel='Region',
|
223 |
-
ylabel='Count of Restaurants',
|
224 |
-
rot=90,
|
225 |
-
height=500,
|
226 |
-
width=900
|
227 |
-
)
|
228 |
-
layout = pn.Column(bar_plot)
|
229 |
-
panel_layout[1:] = [bar_plot]
|
230 |
-
elif event.new == 'Price vs Rating':
|
231 |
-
# Calculate the mean price and rating for each cuisine type
|
232 |
-
price_rating_df = zomato_df.groupby(['CUSINE TYPE', 'RATING'])['PRICE'].mean().reset_index()
|
233 |
-
hvplot_price_rating = price_rating_df.hvplot.line(
|
234 |
-
x='RATING',
|
235 |
-
y='PRICE',
|
236 |
-
by='CUSINE TYPE',
|
237 |
-
title='Price vs Rating by Cuisine Type',
|
238 |
-
xlabel='Rating',
|
239 |
-
ylabel='Price',
|
240 |
-
width=900,
|
241 |
-
height=500,
|
242 |
-
legend='bottom' # Set the position of the legend to 'bottom'
|
243 |
-
)
|
244 |
-
|
245 |
-
# Set the number of legend columns
|
246 |
-
hvplot_price_rating.opts(legend_cols=6) # Adjust the value to your desired maximum number of legend items per row
|
247 |
-
|
248 |
-
# Wrap the Hvplot plot in a Panel object
|
249 |
-
panel_price_vs_rating = pn.panel(hvplot_price_rating)
|
250 |
-
panel_layout[1:] = [panel_price_vs_rating]
|
251 |
-
elif event.new == 'Region vs Price':
|
252 |
-
region_price_df = zomato_df.groupby(['REGION'])['PRICE'].mean().reset_index()
|
253 |
-
scatter_plot = region_price_df.hvplot.scatter(
|
254 |
-
x='REGION',
|
255 |
-
y='PRICE',
|
256 |
-
cmap='Category10',
|
257 |
-
title='Relation between Region and Price',
|
258 |
-
size=100, # Increase the marker size
|
259 |
-
rot=90,
|
260 |
-
width=900,
|
261 |
-
height=600,
|
262 |
-
marker='*',
|
263 |
-
color='red'
|
264 |
-
)
|
265 |
-
panel_region_vs_price = pn.Column(scatter_plot)
|
266 |
-
panel_layout[1:] = [panel_region_vs_price]
|
267 |
-
elif event.new == 'Map':
|
268 |
-
panel_layout[1:] = [panel_map]
|
269 |
|
270 |
yaxis_radio.param.watch(update_chart, 'value')
|
271 |
-
|
272 |
-
# Display the initial chart
|
273 |
-
panel_layout.append(panel_cuisine)
|
274 |
|
275 |
# Display the Panel layout
|
276 |
panel_layout
|
277 |
-
dashboard = panel_layout
|
278 |
import panel as pn
|
279 |
pn.extension() # Add this line to load the Panel extension
|
280 |
|
281 |
# Layout using Template
|
282 |
template = pn.template.FastListTemplate(
|
283 |
-
title='
|
284 |
sidebar=[
|
285 |
-
pn.pane.PNG('
|
286 |
-
pn.pane.Markdown("#
|
287 |
-
pn.pane.Markdown("1.
|
288 |
-
pn.pane.Markdown("2.
|
289 |
-
pn.pane.Markdown("3.
|
290 |
-
pn.pane.Markdown("4.
|
291 |
-
pn.pane.Markdown("5.
|
292 |
-
pn.pane.Markdown("6.
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
pn.pane.Markdown("10. Can we map the best restraunt with high quality food?"),
|
297 |
-
],
|
298 |
-
main = [pn.Row(pn.Column(dashboard)),
|
299 |
-
pn.Row(pn.pane.Markdown("Designed and Developed with ❤️ by Chitranshu Nagdawane © 2023"))
|
300 |
-
],
|
301 |
-
accent_base_color="#E10F14",
|
302 |
-
header_background="#E10F14"
|
303 |
)
|
304 |
|
305 |
template.servable()
|
|
|
|
1 |
import pandas as pd
|
|
|
2 |
import panel as pn
|
3 |
import hvplot.pandas
|
4 |
+
import numpy as np
|
5 |
+
from math import radians, sin, cos, sqrt, asin
|
6 |
+
uber_data = pd.read_csv(r'uber-raw-data-jul14.csv')
|
7 |
+
type(uber_data.loc[0,'Date/Time'])
|
8 |
+
uber_data['Date/Time'] = pd.to_datetime(uber_data['Date/Time'])
|
9 |
+
uber_data['BinnedHour']=uber_data['Date/Time'].dt.floor('15min')
|
10 |
+
uber_data['BinnedHour'].value_counts()
|
11 |
+
DayMap={0:'Monday', 1:'Tuesday', 2:'Wednesday', 3:'Thursday', 4:'Friday', 5:'Saturday', 6:'Sunday'}
|
12 |
+
uber_data['Day']=uber_data['BinnedHour'].dt.weekday.map(DayMap)
|
13 |
+
uber_data['Date']=uber_data['BinnedHour'].dt.date
|
14 |
+
uber_data['Day']=pd.Categorical(uber_data['Day'],categories=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],ordered=True)
|
15 |
+
uber_data['Time']=uber_data['BinnedHour'].dt.time
|
16 |
+
weekly_data1 = uber_data.groupby(['Date','Day','Time']).count().dropna().rename(columns={'BinnedHour':'Rides'})['Rides'].reset_index()
|
17 |
+
daywise = weekly_data1.groupby('Day').sum('Day')
|
18 |
+
# Assuming you have the 'uber_data' DataFrame already defined
|
19 |
+
|
20 |
+
# --- Code 1 ---
|
21 |
+
# Calculate the value counts and sort by index
|
22 |
+
value_counts = uber_data['BinnedHour'].dt.day.value_counts().sort_index()
|
23 |
+
|
24 |
+
# Create a DataFrame from the value counts
|
25 |
+
df = pd.DataFrame({'Days': value_counts.index, 'Rides': value_counts.values})
|
26 |
+
|
27 |
+
# Create a Panel object for the Uber rides graph
|
28 |
+
pn.extension('plotly')
|
29 |
+
pn.config.sizing_mode = 'stretch_width'
|
30 |
+
uber_rides_graph = df.hvplot.bar(x='Days', y='Rides', color='black', xlabel='Days', ylabel='Rides',
|
31 |
+
rot=0, title='Uber Rides per day in July 2014 at NYC',
|
32 |
+
height=400, width=800)
|
33 |
+
|
34 |
+
# --- Code 2 ---
|
35 |
+
# Calculate the value counts and sort by index
|
36 |
+
value_counts = uber_data['BinnedHour'].value_counts().sort_index()
|
37 |
+
|
38 |
+
# Create a DataFrame from the value counts
|
39 |
+
df = pd.DataFrame({'BinnedHour': value_counts.index, 'Rides': value_counts.values})
|
40 |
+
|
41 |
+
# Create a Bokeh figure for the interactive DataFrame graph
|
42 |
+
interactive_df_figure = df.hvplot.line(x='BinnedHour', y='Rides', color='black', alpha=0.8,
|
43 |
+
title='Uber Rides every 15 mins in the month of July at NYC',
|
44 |
+
xlabel='Days', ylabel='No. of Rides',
|
45 |
+
height=400, width=800)
|
46 |
+
|
47 |
+
# Create a Panel object with the Bokeh figure
|
48 |
+
interactive_df_pane = pn.pane.HoloViews(interactive_df_figure)
|
49 |
+
|
50 |
+
# --- Code 3 ---
|
51 |
+
# Extracting day of the week from the 'BinnedHour' column
|
52 |
+
uber_data['BinnedHour'] = pd.to_datetime(uber_data['BinnedHour'])
|
53 |
+
uber_data['BinnedHour'].value_counts()
|
54 |
+
DayMap = {0: 'Monday', 1: 'Tuesday', 2: 'Wednesday', 3: 'Thursday', 4: 'Friday', 5: 'Saturday', 6: 'Sunday'}
|
55 |
+
uber_data['Day'] = uber_data['BinnedHour'].dt.weekday.map(DayMap)
|
56 |
+
uber_data['Date'] = uber_data['BinnedHour'].dt.date
|
57 |
+
uber_data['Day'] = pd.Categorical(uber_data['Day'],
|
58 |
+
categories=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
|
59 |
+
'Sunday'],
|
60 |
+
ordered=True)
|
61 |
+
uber_data['Time'] = uber_data['BinnedHour'].dt.time
|
62 |
+
|
63 |
+
# Grouping by Date, Day, and Time to get the count of rides for each time slot
|
64 |
+
weekly_data = uber_data.groupby(['Date', 'Day', 'Time']).count().dropna().rename(columns={'BinnedHour': 'Rides'})[
|
65 |
+
'Rides'].reset_index()
|
66 |
+
|
67 |
+
# Summing up the rides per day
|
68 |
+
daywise = weekly_data.groupby('Day')['Rides'].sum()
|
69 |
+
df_total_rides = pd.DataFrame({'Days': daywise.index, 'Rides': daywise.values})
|
70 |
+
|
71 |
+
# Create a Panel object for the 'Total Rides per Day' graph
|
72 |
+
total_rides_graph = df_total_rides.hvplot.bar(x='Days', y='Rides', color='black', xlabel='Days', ylabel='Total Rides',
|
73 |
+
rot=0, title='Total Rides per Day',
|
74 |
+
height=400, width=800,
|
75 |
+
value_label=True) # Display total value when hovering
|
76 |
+
|
77 |
+
# --- Code 4 ---
|
78 |
+
# Your original data processing
|
79 |
+
weekly_data = weekly_data.groupby(['Day', 'Time']).mean('Rides')
|
80 |
+
weekly_data1 = weekly_data.unstack(level=0)
|
81 |
+
|
82 |
+
# Create a Panel object
|
83 |
+
avg_rides_graph = pn.panel(weekly_data1.T.mean().hvplot(c='black', xlabel='Date', ylabel='Average rides',
|
84 |
+
xticks=10, title='Average Uber rides on any day in July 2014 at NYC',
|
85 |
+
height=400, width=800))
|
86 |
+
|
87 |
+
# --- Code 5 ---
|
88 |
+
# Countplot using hvplot
|
89 |
+
BaseMapper = {'B02512': 'Unter', 'B02598': 'Hinter', 'B02617': 'Weiter', 'B02682': 'Schmecken', 'B02764': 'Danach-NY'}
|
90 |
+
plot_top_rides_city = uber_data['Base'].map(BaseMapper).value_counts().hvplot(kind='bar', rot=0, xlabel='Base', ylabel='Total rides', color='black',
|
91 |
+
title='CountPlot: Total uber rides vs Base - July 2014, NYC', height=400, width=800)
|
92 |
+
|
93 |
+
# --- Code 6 ---
|
94 |
+
# Your code 6 as provided
|
95 |
+
metro_art_coordinates = (40.7794, -73.9632)
|
96 |
+
empire_state_building_coordinates = (40.7484, -73.9857)
|
97 |
+
|
98 |
+
def haversine(coordinates1, coordinates2):
|
99 |
+
lat1, lon1 = coordinates1
|
100 |
+
lat2, lon2 = coordinates2
|
101 |
+
|
102 |
+
# Convert to radians and apply Haversine formula
|
103 |
+
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
|
104 |
+
dlon = lon2 - lon1
|
105 |
+
dlat = lat2 - lat1
|
106 |
+
|
107 |
+
a = sin(dlat/2)**2 + cos(lat1)*cos(lat2)*sin(dlon/2)**2
|
108 |
+
c = 2 * asin(sqrt(a))
|
109 |
+
r = 3956
|
110 |
+
return c * r
|
111 |
|
112 |
+
# Assuming `uber_data` is a DataFrame containing 'Lat' and 'Lon' columns
|
113 |
+
# Calculate distances from 'metro_art_coordinates' and 'empire_state_building_coordinates'
|
114 |
+
uber_data['Distance MM'] = uber_data[['Lat', 'Lon']].apply(lambda x: haversine(metro_art_coordinates, tuple(x)), axis=1)
|
115 |
+
uber_data['Distance ESB'] = uber_data[['Lat', 'Lon']].apply(lambda x: haversine(empire_state_building_coordinates, tuple(x)), axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
# Count the number of rides within 0.25 miles of each location
|
118 |
+
# print((uber_data[['Distance MM', 'Distance ESB']] < 0.25).sum())
|
119 |
|
120 |
+
# Create distance range and count the number of rides within each distance
|
121 |
+
distance_range = np.arange(0.1, 5.1, 0.1)
|
122 |
+
distance_data = [(uber_data[['Distance MM', 'Distance ESB']] < dist).sum() for dist in distance_range]
|
123 |
+
distance_data = pd.concat(distance_data, axis=1)
|
124 |
+
distance_data = distance_data.T
|
125 |
+
distance_data.index = distance_range
|
126 |
+
distance_data = distance_data.rename(columns={'Distance MM': 'CloserToMM', 'Distance ESB': 'CloserToESB'})
|
127 |
|
128 |
+
pn.extension('bokeh')
|
|
|
129 |
|
130 |
+
# Create the hvplot figure with customized colors
|
131 |
+
fig = distance_data.hvplot(height=400, width=800, color=['black', 'grey']).opts(title='Number of Rides Closer to ESB and MM',
|
132 |
+
xlabel='Threshold Radius(mi)',
|
133 |
+
ylabel='Rides')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
+
# Create a panel with the figure
|
136 |
+
fig_panel = pn.panel(fig)
|
137 |
|
138 |
# Define Panel widgets
|
139 |
yaxis_radio = pn.widgets.RadioButtonGroup(
|
140 |
name='Y axis',
|
141 |
+
options=['Rides vs Days', '15 min of Uber', 'Total Rides per Day', 'Avg Rides per Day', 'Top Rides City', 'Predicting Distance'],
|
142 |
+
button_type='light',
|
143 |
+
button_style='solid',
|
144 |
+
inline=True
|
145 |
)
|
146 |
|
147 |
# Define the Panel layout
|
148 |
panel_layout = pn.Column(
|
149 |
+
yaxis_radio,
|
150 |
+
pn.pane.HoloViews(uber_rides_graph),
|
151 |
)
|
152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
# Define the callback function for the radio button
|
154 |
def update_chart(event):
|
155 |
+
if event.new == 'Rides vs Days':
|
156 |
+
panel_layout[1] = pn.pane.HoloViews(uber_rides_graph)
|
157 |
+
elif event.new == '15 min of Uber':
|
158 |
+
panel_layout[1] = interactive_df_pane
|
159 |
+
elif event.new == 'Total Rides per Day':
|
160 |
+
panel_layout[1] = total_rides_graph
|
161 |
+
elif event.new == 'Avg Rides per Day':
|
162 |
+
panel_layout[1] = avg_rides_graph
|
163 |
+
elif event.new == 'Top Rides City':
|
164 |
+
panel_layout[1] = plot_top_rides_city
|
165 |
+
elif event.new == 'Predicting Distance':
|
166 |
+
panel_layout[1] = fig_panel
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
yaxis_radio.param.watch(update_chart, 'value')
|
169 |
+
panel_layout.append
|
|
|
|
|
170 |
|
171 |
# Display the Panel layout
|
172 |
panel_layout
|
|
|
173 |
import panel as pn
|
174 |
pn.extension() # Add this line to load the Panel extension
|
175 |
|
176 |
# Layout using Template
|
177 |
template = pn.template.FastListTemplate(
|
178 |
+
title='Uber Analysis Dashboard',
|
179 |
sidebar=[
|
180 |
+
pn.pane.PNG('Uber2.png', sizing_mode='scale_both'),
|
181 |
+
pn.pane.Markdown("# Key Performance Indicators (KPIs) of the EDA"),
|
182 |
+
pn.pane.Markdown("1. Let us visualize the total uber rides per day in the month of July 2014"),
|
183 |
+
pn.pane.Markdown("2. Let us have a more closer look at it, say every 15 minutes from July 1 to July 31."),
|
184 |
+
pn.pane.Markdown("3. Grouping weekly_data by days to plot total rides per week in july 2014."),
|
185 |
+
pn.pane.Markdown("4. Finding average rides on any day."),
|
186 |
+
pn.pane.Markdown("5. Now, let's try visualizing the relationship between Base and total number of rides in July 2014"),
|
187 |
+
pn.pane.Markdown("6. The number of rides predicted to Metropolitan Museum (MM) and Empire State Building (ESB)")],
|
188 |
+
main = [pn.Row(pn.Column(panel_layout))],
|
189 |
+
accent_base_color="#000000",
|
190 |
+
header_background="#000000"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
)
|
192 |
|
193 |
template.servable()
|
194 |
+
|