Spaces:
Sleeping
Sleeping
Changes
Browse files
app.py
CHANGED
@@ -2,11 +2,13 @@ import pandas as pd
|
|
2 |
import streamlit as st
|
3 |
import altair as alt
|
4 |
|
|
|
|
|
5 |
# Load and clean dataset
|
6 |
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
7 |
df = pd.read_csv(url, na_values={'Year Acquired': 0, 'Year Constructed': 0, 'Square Footage': 0})
|
8 |
# st.set_page_config(page_title="Building Inventory Analysis", layout="wide")
|
9 |
-
|
10 |
|
11 |
|
12 |
# Displaying the Dataset Overview
|
@@ -46,20 +48,34 @@ st.markdown("""
|
|
46 |
# Group the data by 'County' and 'Agency Name' to get the count of buildings
|
47 |
county_agency_building = df.groupby(['County', 'Agency Name']).size().reset_index(name='Number of Buildings')
|
48 |
|
|
|
|
|
49 |
# Create a stacked bar chart with adjusted legend properties
|
50 |
-
stacked_bar_chart_county =
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
# Display the stacked bar chart in Streamlit
|
62 |
-
st.altair_chart(stacked_bar_chart_county,use_container_width=True)
|
63 |
|
64 |
# Write-up for Stacked Bar Chart
|
65 |
|
@@ -98,7 +114,7 @@ bubble_chart = alt.Chart(df).mark_circle().encode(
|
|
98 |
title="Relationship Between County, Square Footage, and Total Floors"
|
99 |
).interactive()
|
100 |
|
101 |
-
st.altair_chart(bubble_chart,use_container_width=True)
|
102 |
|
103 |
|
104 |
# Write-up for Bubble Chart
|
@@ -135,7 +151,7 @@ heatmap = alt.Chart(df).mark_rect().encode(
|
|
135 |
title="Heatmap of Building Count by County and Status"
|
136 |
)
|
137 |
|
138 |
-
st.altair_chart(heatmap, use_container_width=True)
|
139 |
|
140 |
|
141 |
|
@@ -162,20 +178,3 @@ st.markdown("""
|
|
162 |
**~By Janhavi Tushar Zarapkar**
|
163 |
""", unsafe_allow_html=True)
|
164 |
|
165 |
-
|
166 |
-
st.markdown("<h4 style='text-decoration: underline;'>Visualization 2</h4>", unsafe_allow_html=True)
|
167 |
-
county_agency_data = df.dropna(subset=['County', 'Agency Name'])
|
168 |
-
county_agency_count = county_agency_data.groupby('County')['Agency Name'].nunique().reset_index()
|
169 |
-
county_agency_count.rename(columns={'Agency Name': 'Unique Agencies'}, inplace=True)
|
170 |
-
|
171 |
-
county_agency_chart = alt.Chart(county_agency_count).mark_bar().encode(
|
172 |
-
x=alt.X('County:N', sort='-y', title="County"),
|
173 |
-
y=alt.Y('Unique Agencies:Q', title="Number of Agencies"),
|
174 |
-
color=alt.Color('Unique Agencies:Q', scale=alt.Scale(scheme='viridis')),
|
175 |
-
tooltip=['County:N', 'Unique Agencies:Q']
|
176 |
-
).properties(
|
177 |
-
width=700,
|
178 |
-
height=400,
|
179 |
-
title="Unique Agencies in Each County"
|
180 |
-
)
|
181 |
-
st.altair_chart(county_agency_chart, use_container_width=True)
|
|
|
2 |
import streamlit as st
|
3 |
import altair as alt
|
4 |
|
5 |
+
st.title("Building Inventory Analysis")
|
6 |
+
|
7 |
# Load and clean dataset
|
8 |
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
9 |
df = pd.read_csv(url, na_values={'Year Acquired': 0, 'Year Constructed': 0, 'Square Footage': 0})
|
10 |
# st.set_page_config(page_title="Building Inventory Analysis", layout="wide")
|
11 |
+
|
12 |
|
13 |
|
14 |
# Displaying the Dataset Overview
|
|
|
48 |
# Group the data by 'County' and 'Agency Name' to get the count of buildings
|
49 |
county_agency_building = df.groupby(['County', 'Agency Name']).size().reset_index(name='Number of Buildings')
|
50 |
|
51 |
+
|
52 |
+
|
53 |
# Create a stacked bar chart with adjusted legend properties
|
54 |
+
stacked_bar_chart_county = (
|
55 |
+
alt.Chart(county_agency_building)
|
56 |
+
.mark_bar()
|
57 |
+
.encode(
|
58 |
+
alt.X('County:N', title='County', sort='-y'),
|
59 |
+
alt.Y(
|
60 |
+
'Number of Buildings:Q',
|
61 |
+
title='Number of Buildings',
|
62 |
+
scale=alt.Scale(domain=[0, 550]),
|
63 |
+
),
|
64 |
+
color =
|
65 |
+
alt.Color(
|
66 |
+
'Agency Name:N',
|
67 |
+
title='Agency Name',
|
68 |
+
legend=alt.Legend(orient='right', padding=0, symbolSize=50,labelFontSize=10,labelOverlap="greedy", columnPadding=0,rowPadding=0)
|
69 |
+
),
|
70 |
+
tooltip=['County', 'Agency Name', 'Number of Buildings']
|
71 |
+
).properties(
|
72 |
+
width=800,
|
73 |
+
height=500,
|
74 |
+
title="Stacked Bar Graph for Number of Buildings by County and Agency"
|
75 |
+
))
|
76 |
|
77 |
# Display the stacked bar chart in Streamlit
|
78 |
+
st.altair_chart(stacked_bar_chart_county,theme="streamlit", use_container_width=True)
|
79 |
|
80 |
# Write-up for Stacked Bar Chart
|
81 |
|
|
|
114 |
title="Relationship Between County, Square Footage, and Total Floors"
|
115 |
).interactive()
|
116 |
|
117 |
+
st.altair_chart(bubble_chart,theme="streamlit", use_container_width=True)
|
118 |
|
119 |
|
120 |
# Write-up for Bubble Chart
|
|
|
151 |
title="Heatmap of Building Count by County and Status"
|
152 |
)
|
153 |
|
154 |
+
st.altair_chart(heatmap, theme="streamlit", use_container_width=True)
|
155 |
|
156 |
|
157 |
|
|
|
178 |
**~By Janhavi Tushar Zarapkar**
|
179 |
""", unsafe_allow_html=True)
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|