Spaces:
Sleeping
Sleeping
Aniruddha commited on
Commit ·
d21976f
1
Parent(s): d5327f8
1st commit
Browse files
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import altair as alt
|
| 4 |
+
|
| 5 |
+
st.set_page_config(layout="wide")
|
| 6 |
+
|
| 7 |
+
# App title
|
| 8 |
+
st.title('Building Inventory Visualization – IS445 Homework')
|
| 9 |
+
|
| 10 |
+
# Load dataset
|
| 11 |
+
DATA_URL = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv"
|
| 12 |
+
df = pd.read_csv(DATA_URL)
|
| 13 |
+
df.columns = df.columns.str.strip()
|
| 14 |
+
|
| 15 |
+
# Dataset preview
|
| 16 |
+
st.markdown("### Dataset Preview")
|
| 17 |
+
st.dataframe(df.head())
|
| 18 |
+
|
| 19 |
+
# === Chart 1: Number of Buildings by Usage Description ===
|
| 20 |
+
st.markdown("### 1. Number of Buildings by Usage Description")
|
| 21 |
+
|
| 22 |
+
chart1 = (
|
| 23 |
+
alt.Chart(df)
|
| 24 |
+
.mark_bar()
|
| 25 |
+
.encode(
|
| 26 |
+
x=alt.X('Usage Description:N', sort='-y', title='Usage Description'),
|
| 27 |
+
y=alt.Y('count()', title='Number of Buildings'),
|
| 28 |
+
color=alt.Color('Usage Description:N', legend=None)
|
| 29 |
+
)
|
| 30 |
+
.properties(width=700, height=400, title="Number of Buildings by Usage Description")
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
st.altair_chart(chart1, use_container_width=True)
|
| 34 |
+
|
| 35 |
+
# === Write-up for Chart 1 (Humanized + Justified) ===
|
| 36 |
+
st.markdown("#### Write-up for Chart 1")
|
| 37 |
+
st.markdown(
|
| 38 |
+
"""
|
| 39 |
+
<div style='text-align: justify'>
|
| 40 |
+
This chart displays how many buildings are assigned to each type of use, like storage, education, or business.
|
| 41 |
+
I picked a bar chart for this because it makes it easy to compare different categories at a glance. The categories
|
| 42 |
+
are sorted from most to least frequent so that it’s easier to see which uses are most common. I also used colors
|
| 43 |
+
to help distinguish between them visually, without adding a separate legend.
|
| 44 |
+
|
| 45 |
+
If I had more time, I would try to add filters for different locations like city or county. That way, people could
|
| 46 |
+
explore the building usage more specifically. I also think some usage categories are very similar, so grouping them
|
| 47 |
+
might make things cleaner and more understandable.
|
| 48 |
+
</div>
|
| 49 |
+
""",
|
| 50 |
+
unsafe_allow_html=True
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# === Chart 2: Average Square Footage by Usage Description ===
|
| 54 |
+
st.markdown("### 2. Average Square Footage by Usage Description")
|
| 55 |
+
|
| 56 |
+
avg_sqft = df.groupby("Usage Description")["Square Footage"].mean().reset_index()
|
| 57 |
+
|
| 58 |
+
chart2 = (
|
| 59 |
+
alt.Chart(avg_sqft)
|
| 60 |
+
.mark_bar()
|
| 61 |
+
.encode(
|
| 62 |
+
x=alt.X('Usage Description:N', sort='-y', title='Usage Description'),
|
| 63 |
+
y=alt.Y('Square Footage:Q', title='Average Square Footage'),
|
| 64 |
+
color=alt.Color('Usage Description:N', legend=None)
|
| 65 |
+
)
|
| 66 |
+
.properties(width=700, height=400, title="Average Square Footage by Usage Description")
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
st.altair_chart(chart2, use_container_width=True)
|
| 70 |
+
|
| 71 |
+
# === Write-up for Chart 2 (Humanized + Justified) ===
|
| 72 |
+
st.markdown("#### Write-up for Chart 2")
|
| 73 |
+
st.markdown(
|
| 74 |
+
"""
|
| 75 |
+
<div style='text-align: justify'>
|
| 76 |
+
This chart shows how big the buildings are on average, depending on what they’re used for. Education buildings,
|
| 77 |
+
for example, tend to be a lot bigger than something like utility or public use buildings. I stuck with a bar
|
| 78 |
+
chart again for consistency, and sorted it from largest to smallest so you can quickly pick out the biggest categories.
|
| 79 |
+
|
| 80 |
+
If I had more time, I would include a tooltip or label that shows how many buildings are in each group, since
|
| 81 |
+
average size alone doesn’t always give the full picture. Maybe I’d even try a box plot instead of a bar chart
|
| 82 |
+
to show the range of building sizes, not just the average. An interactive dropdown to toggle between mean and
|
| 83 |
+
median could also make this more flexible for the user.
|
| 84 |
+
</div>
|
| 85 |
+
""",
|
| 86 |
+
unsafe_allow_html=True
|
| 87 |
+
)
|