krisin commited on
Commit
74ea55d
·
verified ·
1 Parent(s): b2caf87

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -18
app.py CHANGED
@@ -109,8 +109,11 @@ elif page == "Dataset":
109
  # Page: Visualization 1
110
  # ----------------------------
111
  elif page == "Visualization 1":
112
- st.title("Transportation Usage Over Time")
113
- st.markdown("This stacked area chart shows how walking and bicycling have changed over time nationally.")
 
 
 
114
 
115
  # Prepare the data
116
  df_clean = df.copy()
@@ -118,23 +121,20 @@ elif page == "Visualization 1":
118
  df_clean["Value"] = pd.to_numeric(df_clean["Value"], errors="coerce")
119
  df_clean["Transportation Type"] = df_clean["Transportation Type"].str.strip()
120
 
121
- # Group and pivot
122
- area_df = df_clean.groupby(["End Year", "Transportation Type"])["Value"].sum().reset_index()
123
- area_pivot = area_df.pivot(index="End Year", columns="Transportation Type", values="Value").fillna(0)
124
-
125
- # Plot using Altair for interactivity
126
- import altair as alt
127
- area_chart = alt.Chart(area_df).mark_area(opacity=0.6).encode(
128
- x=alt.X('End Year:O', title='End Year'),
129
- y=alt.Y('Value:Q', stack='zero', title='Total Value'),
130
- color='Transportation Type:N'
131
- ).properties(
132
- width=700,
133
- height=400,
134
- title='Transportation Usage Over Time (Stacked Area)'
135
- )
136
 
137
- st.altair_chart(area_chart, use_container_width=True)
138
 
139
  # ----------------------------
140
  # Page: Visualization 2
 
109
  # Page: Visualization 1
110
  # ----------------------------
111
  elif page == "Visualization 1":
112
+ st.title("Top States: Transportation Usage Over Time")
113
+ st.markdown("This line chart compares walking and bicycling trends across the top 5 states with the highest total transportation usage.")
114
+
115
+ import seaborn as sns
116
+ import matplotlib.pyplot as plt
117
 
118
  # Prepare the data
119
  df_clean = df.copy()
 
121
  df_clean["Value"] = pd.to_numeric(df_clean["Value"], errors="coerce")
122
  df_clean["Transportation Type"] = df_clean["Transportation Type"].str.strip()
123
 
124
+ # Identify top 5 states by total Value
125
+ top_states = df_clean.groupby('State')['Value'].sum().nlargest(5).index
126
+ filtered_df = df_clean[df_clean['State'].isin(top_states)]
127
+
128
+ # Plot
129
+ fig, ax = plt.subplots(figsize=(12, 6))
130
+ sns.lineplot(data=filtered_df, x='End Year', y='Value', hue='Transportation Type',
131
+ style='State', markers=True, dashes=False, ax=ax)
132
+ ax.set_title('Top States: Transportation Usage Over Time')
133
+ ax.set_xlabel('End Year')
134
+ ax.set_ylabel('Value')
135
+ ax.grid(True)
136
+ st.pyplot(fig)
 
 
137
 
 
138
 
139
  # ----------------------------
140
  # Page: Visualization 2