Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,32 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
-
import plotly.graph_objects as go
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
-
import seaborn as sns
|
| 6 |
import os
|
| 7 |
|
| 8 |
-
st.
|
| 9 |
-
|
| 10 |
-
st.title("Legislative Bill Analysis Dashboard")
|
| 11 |
|
| 12 |
DATA_PATH = "Illinois_Entire_Data_Insights_Final_v2.csv"
|
| 13 |
|
| 14 |
-
if os.path.exists(DATA_PATH):
|
| 15 |
-
|
| 16 |
-
st.
|
| 17 |
-
|
| 18 |
-
# Sankey Diagram
|
| 19 |
-
st.header("🔗 Sankey Diagram: Intent → Stance → Beneficiaries")
|
| 20 |
-
sankey_df = df[['intent_standardized', 'stance_standardized', 'intended_beneficiaries_standardized']].dropna()
|
| 21 |
-
|
| 22 |
-
if not sankey_df.empty:
|
| 23 |
-
labels = list(pd.unique(sankey_df['intent_standardized'].tolist() +
|
| 24 |
-
sankey_df['stance_standardized'].tolist() +
|
| 25 |
-
sankey_df['intended_beneficiaries_standardized'].tolist()))
|
| 26 |
-
label_map = {label: i for i, label in enumerate(labels)}
|
| 27 |
-
|
| 28 |
-
intent_stance = sankey_df.groupby(['intent_standardized', 'stance_standardized']).size().reset_index(name='count')
|
| 29 |
-
stance_beneficiary = sankey_df.groupby(['stance_standardized', 'intended_beneficiaries_standardized']).size().reset_index(name='count')
|
| 30 |
-
|
| 31 |
-
source = intent_stance['intent_standardized'].map(label_map).tolist() + stance_beneficiary['stance_standardized'].map(label_map).tolist()
|
| 32 |
-
target = intent_stance['stance_standardized'].map(label_map).tolist() + stance_beneficiary['intended_beneficiaries_standardized'].map(label_map).tolist()
|
| 33 |
-
value = intent_stance['count'].tolist() + stance_beneficiary['count'].tolist()
|
| 34 |
-
|
| 35 |
-
fig_sankey = go.Figure(data=[go.Sankey(
|
| 36 |
-
node=dict(pad=15, thickness=20, line=dict(color="black", width=0.5), label=labels),
|
| 37 |
-
link=dict(source=source, target=target, value=value)
|
| 38 |
-
)])
|
| 39 |
-
fig_sankey.update_layout(title_text="Sankey: Intent → Stance → Beneficiary", font_size=12)
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
st.warning("Sankey input columns contain only null values or are missing.")
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
|
| 50 |
-
heat = heat_df.pivot_table(index='category_&_subcategory_standardized',
|
| 51 |
-
columns='policy_impact_areas_standardized',
|
| 52 |
-
aggfunc=len,
|
| 53 |
-
fill_value=0)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
sns.heatmap(heat, cmap='coolwarm', annot=False)
|
| 57 |
-
plt.title("Heatmap: Category vs Policy Impact Area")
|
| 58 |
-
plt.xlabel("Policy Impact Area")
|
| 59 |
-
plt.ylabel("Category")
|
| 60 |
-
plt.tight_layout()
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
| 67 |
-
st.error(f"Data file {DATA_PATH} not found in Space repo.")
|
| 68 |
-
st.stop()
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
|
|
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
st.title("Basic Bar Chart from Legislative Data")
|
|
|
|
|
|
|
| 7 |
|
| 8 |
DATA_PATH = "Illinois_Entire_Data_Insights_Final_v2.csv"
|
| 9 |
|
| 10 |
+
if not os.path.exists(DATA_PATH):
|
| 11 |
+
st.error(f"Data file {DATA_PATH} not found in repo.")
|
| 12 |
+
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
df = pd.read_csv(DATA_PATH)
|
| 15 |
+
st.success(f"Loaded {DATA_PATH}")
|
|
|
|
| 16 |
|
| 17 |
+
# For example: count of bills by 'intent_standardized'
|
| 18 |
+
if 'intent_standardized' not in df.columns:
|
| 19 |
+
st.error("Column 'intent_standardized' not found in data.")
|
| 20 |
+
st.stop()
|
| 21 |
|
| 22 |
+
counts = df['intent_standardized'].value_counts()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
st.write("### Count of Bills by Intent")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
fig, ax = plt.subplots()
|
| 27 |
+
counts.plot(kind='bar', ax=ax)
|
| 28 |
+
ax.set_xlabel("Intent")
|
| 29 |
+
ax.set_ylabel("Count")
|
| 30 |
+
plt.xticks(rotation=45)
|
| 31 |
|
| 32 |
+
st.pyplot(fig)
|
|
|
|
|
|