Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,12 +3,12 @@ import pandas as pd
|
|
3 |
import altair as alt
|
4 |
|
5 |
# Title and Introduction
|
6 |
-
st.title("Building Inventory
|
7 |
st.markdown("""
|
8 |
-
This
|
9 |
-
1.
|
10 |
-
2.
|
11 |
-
|
12 |
""")
|
13 |
|
14 |
# Load Dataset
|
@@ -20,71 +20,68 @@ def load_data():
|
|
20 |
data = load_data()
|
21 |
|
22 |
# Data Preprocessing
|
23 |
-
|
24 |
-
data['
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
yearly_square_footage = data_clean.groupby('Year Acquired')['Square Footage'].sum().reset_index()
|
36 |
-
|
37 |
-
# Visualization: Total Square Footage Acquired Over Time
|
38 |
-
st.header("Total Square Footage Acquired Over Time")
|
39 |
-
line_chart = alt.Chart(yearly_square_footage).mark_line(point=True, color='seagreen').encode(
|
40 |
-
alt.X('Year Acquired:Q', title="Year Acquired"),
|
41 |
-
alt.Y('Square Footage:Q', title="Total Square Footage"),
|
42 |
-
tooltip=['Year Acquired', 'Square Footage']
|
43 |
).properties(
|
44 |
width=700,
|
45 |
height=400,
|
46 |
-
title=
|
47 |
).interactive()
|
48 |
|
49 |
-
st.altair_chart(
|
50 |
|
51 |
st.markdown("""
|
52 |
-
|
53 |
-
This
|
54 |
- **Design Choices**:
|
55 |
-
- A
|
56 |
-
-
|
57 |
-
- The
|
58 |
-
- Interactive tooltips offer precise
|
59 |
- **Potential Improvements**:
|
60 |
-
-
|
61 |
-
-
|
62 |
""")
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
alt.Y('Square Footage:Q', title="Square Footage"),
|
70 |
-
color='Usage Description:N'
|
71 |
).properties(
|
72 |
width=700,
|
73 |
height=400,
|
74 |
-
title=
|
75 |
-
)
|
76 |
-
|
|
|
77 |
|
78 |
st.markdown("""
|
79 |
-
|
80 |
-
This
|
81 |
- **Design Choices**:
|
82 |
-
- A
|
83 |
-
-
|
84 |
-
- The
|
|
|
85 |
- **Potential Improvements**:
|
86 |
-
-
|
87 |
-
-
|
88 |
""")
|
89 |
|
90 |
# Footer
|
|
|
3 |
import altair as alt
|
4 |
|
5 |
# Title and Introduction
|
6 |
+
st.title("Building Inventory Analysis")
|
7 |
st.markdown("""
|
8 |
+
This application provides insights into the building inventory dataset through two visualizations:
|
9 |
+
1. **Building Count by County**: Displays the number of buildings in each county.
|
10 |
+
2. **Year-wise Construction of Buildings**: Shows the count of buildings constructed each year.
|
11 |
+
Each visualization is accompanied by a brief explanation, including design choices and potential improvements.
|
12 |
""")
|
13 |
|
14 |
# Load Dataset
|
|
|
20 |
data = load_data()
|
21 |
|
22 |
# Data Preprocessing
|
23 |
+
# Ensure 'Year Constructed' is numeric
|
24 |
+
data['Year Constructed'] = pd.to_numeric(data['Year Constructed'], errors='coerce')
|
25 |
|
26 |
+
# Visualization 1: Building Count by County
|
27 |
+
st.header("1. Building Count by County")
|
28 |
+
county_count = data['County'].value_counts().reset_index()
|
29 |
+
county_count.columns = ['County', 'Building Count']
|
30 |
|
31 |
+
county_chart = alt.Chart(county_count).mark_bar(color='teal').encode(
|
32 |
+
alt.X('Building Count:Q', title='Number of Buildings'),
|
33 |
+
alt.Y('County:N', sort='-x', title='County'),
|
34 |
+
tooltip=['County', 'Building Count']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
).properties(
|
36 |
width=700,
|
37 |
height=400,
|
38 |
+
title='Number of Buildings per County'
|
39 |
).interactive()
|
40 |
|
41 |
+
st.altair_chart(county_chart, use_container_width=True)
|
42 |
|
43 |
st.markdown("""
|
44 |
+
**Explanation**:
|
45 |
+
This bar chart illustrates the number of buildings in each county, highlighting areas with higher concentrations of government buildings.
|
46 |
- **Design Choices**:
|
47 |
+
- A horizontal bar chart is used to accommodate long county names and facilitate easy comparison.
|
48 |
+
- Counties are sorted in descending order based on building count to emphasize those with the most buildings.
|
49 |
+
- The teal color provides a calm and professional appearance.
|
50 |
+
- Interactive tooltips offer precise counts upon hovering.
|
51 |
- **Potential Improvements**:
|
52 |
+
- Incorporate filters to allow users to focus on specific regions or agencies.
|
53 |
+
- Add a map visualization to provide spatial context to the data.
|
54 |
""")
|
55 |
|
56 |
+
# Visualization 2: Year-wise Construction of Buildings
|
57 |
+
st.header("2. Year-wise Construction of Buildings")
|
58 |
+
yearly_construction = data['Year Constructed'].dropna().astype(int).value_counts().reset_index()
|
59 |
+
yearly_construction.columns = ['Year Constructed', 'Building Count']
|
60 |
+
yearly_construction = yearly_construction.sort_values('Year Constructed')
|
61 |
|
62 |
+
year_chart = alt.Chart(yearly_construction).mark_line(point=True, color='orange').encode(
|
63 |
+
alt.X('Year Constructed:Q', title='Year Constructed'),
|
64 |
+
alt.Y('Building Count:Q', title='Number of Buildings'),
|
65 |
+
tooltip=['Year Constructed', 'Building Count']
|
|
|
|
|
66 |
).properties(
|
67 |
width=700,
|
68 |
height=400,
|
69 |
+
title='Number of Buildings Constructed Over Time'
|
70 |
+
).interactive()
|
71 |
+
|
72 |
+
st.altair_chart(year_chart, use_container_width=True)
|
73 |
|
74 |
st.markdown("""
|
75 |
+
**Explanation**:
|
76 |
+
This line chart displays the number of buildings constructed each year, revealing trends and periods of increased construction activity.
|
77 |
- **Design Choices**:
|
78 |
+
- A line chart effectively shows changes over time and highlights trends.
|
79 |
+
- Data points are marked to emphasize individual years.
|
80 |
+
- The orange color draws attention to the trend line.
|
81 |
+
- Interactive tooltips provide exact counts for each year.
|
82 |
- **Potential Improvements**:
|
83 |
+
- Implement a rolling average to smooth out year-to-year fluctuations.
|
84 |
+
- Allow users to filter the data by building type or agency to explore specific trends.
|
85 |
""")
|
86 |
|
87 |
# Footer
|