Basak Tamer commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -41,6 +41,7 @@ with st.expander("📊 View Strategic Executive Summary", expanded=True):
|
|
| 41 |
@st.cache_data
|
| 42 |
def load_data():
|
| 43 |
try:
|
|
|
|
| 44 |
data = pd.read_csv('uber-raw-data-sep14.csv')
|
| 45 |
data['Date/Time'] = pd.to_datetime(data['Date/Time'])
|
| 46 |
data['Hour'] = data['Date/Time'].dt.hour
|
|
@@ -55,6 +56,8 @@ df = load_data()
|
|
| 55 |
# --- MAIN CONTENT BLOCK ---
|
| 56 |
if df is not None:
|
| 57 |
st.divider()
|
|
|
|
|
|
|
| 58 |
col1, col2 = st.columns([2, 1])
|
| 59 |
|
| 60 |
with col1:
|
|
@@ -71,10 +74,27 @@ if df is not None:
|
|
| 71 |
fig_pie = px.pie(base_data, values='count', names='Base', hole=0.4)
|
| 72 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 73 |
|
| 74 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
st.divider()
|
| 76 |
st.markdown("### 🎬 The Race: Cumulative Hourly Growth")
|
| 77 |
-
# This is the line that had the error - ensure it is ONE line:
|
| 78 |
st.info("This animation demonstrates the 'Hourly Trip Density' evolution across NYC's dispatch bases.")
|
| 79 |
|
| 80 |
video_path = 'uber_race.mp4'
|
|
@@ -82,7 +102,7 @@ if df is not None:
|
|
| 82 |
with open(video_path, 'rb') as video_file:
|
| 83 |
st.video(video_file.read())
|
| 84 |
else:
|
| 85 |
-
st.warning("Video file 'uber_race.mp4' not found
|
| 86 |
|
| 87 |
# --- SIDEBAR ---
|
| 88 |
st.sidebar.markdown("---")
|
|
|
|
| 41 |
@st.cache_data
|
| 42 |
def load_data():
|
| 43 |
try:
|
| 44 |
+
# Load data
|
| 45 |
data = pd.read_csv('uber-raw-data-sep14.csv')
|
| 46 |
data['Date/Time'] = pd.to_datetime(data['Date/Time'])
|
| 47 |
data['Hour'] = data['Date/Time'].dt.hour
|
|
|
|
| 56 |
# --- MAIN CONTENT BLOCK ---
|
| 57 |
if df is not None:
|
| 58 |
st.divider()
|
| 59 |
+
|
| 60 |
+
# ROW 1: BAR AND PIE
|
| 61 |
col1, col2 = st.columns([2, 1])
|
| 62 |
|
| 63 |
with col1:
|
|
|
|
| 74 |
fig_pie = px.pie(base_data, values='count', names='Base', hole=0.4)
|
| 75 |
st.plotly_chart(fig_pie, use_container_width=True)
|
| 76 |
|
| 77 |
+
# ROW 2: SUNBURST (THE NEW SECTION)
|
| 78 |
+
st.divider()
|
| 79 |
+
st.markdown("### ☀️ Journey Hierarchy: Day, Hour, and Base")
|
| 80 |
+
st.write("Interactively explore the relationship between the time of day and dispatch activity.")
|
| 81 |
+
|
| 82 |
+
# Pre-aggregating for the Sunburst to ensure high performance
|
| 83 |
+
sun_data = df.groupby(['DayOfWeek', 'Hour', 'Base']).size().reset_index(name='Trips')
|
| 84 |
+
|
| 85 |
+
fig_sun = px.sunburst(
|
| 86 |
+
sun_data,
|
| 87 |
+
path=['DayOfWeek', 'Hour', 'Base'],
|
| 88 |
+
values='Trips',
|
| 89 |
+
color='Trips',
|
| 90 |
+
color_continuous_scale='RdBu',
|
| 91 |
+
template='plotly_white'
|
| 92 |
+
)
|
| 93 |
+
st.plotly_chart(fig_sun, use_container_width=True)
|
| 94 |
+
|
| 95 |
+
# ROW 3: THE RACING BAR SECTION
|
| 96 |
st.divider()
|
| 97 |
st.markdown("### 🎬 The Race: Cumulative Hourly Growth")
|
|
|
|
| 98 |
st.info("This animation demonstrates the 'Hourly Trip Density' evolution across NYC's dispatch bases.")
|
| 99 |
|
| 100 |
video_path = 'uber_race.mp4'
|
|
|
|
| 102 |
with open(video_path, 'rb') as video_file:
|
| 103 |
st.video(video_file.read())
|
| 104 |
else:
|
| 105 |
+
st.warning("Video file 'uber_race.mp4' not found.")
|
| 106 |
|
| 107 |
# --- SIDEBAR ---
|
| 108 |
st.sidebar.markdown("---")
|