Update app.py
Browse files
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
|
|
|
|
|
|
|
|
|
|
| 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 |
-
#
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
# Plot
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 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
|