msa17 commited on
Commit
91a71ee
·
verified ·
1 Parent(s): 0e82be3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -49
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 Visualization")
7
  st.markdown("""
8
- This app visualizes building inventory data. We explore two key visualizations:
9
- 1. The distribution of buildings based on their acquisition year.
10
- 2. A comparison of the square footage for buildings across different usage descriptions.
11
- Below, we also provide explanations for each visualization, including design choices and potential improvements.
12
  """)
13
 
14
  # Load Dataset
@@ -20,71 +20,68 @@ def load_data():
20
  data = load_data()
21
 
22
  # Data Preprocessing
23
- data['Year Acquired'] = pd.to_numeric(data['Year Acquired'], errors='coerce')
24
- data['Square Footage'] = pd.to_numeric(data['Square Footage'], errors='coerce')
25
 
26
- # Data Preprocessing for New Visualization
27
- # Convert 'Year Acquired' and 'Square Footage' to numeric, handling errors
28
- data['Year Acquired'] = pd.to_numeric(data['Year Acquired'], errors='coerce')
29
- data['Square Footage'] = pd.to_numeric(data['Square Footage'], errors='coerce')
30
 
31
- # Remove rows with missing or invalid data in 'Year Acquired' or 'Square Footage'
32
- data_clean = data.dropna(subset=['Year Acquired', 'Square Footage'])
33
-
34
- # Group by 'Year Acquired' and sum 'Square Footage'
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="Total Square Footage Acquired Over Time"
47
  ).interactive()
48
 
49
- st.altair_chart(line_chart, use_container_width=True)
50
 
51
  st.markdown("""
52
- ### Explanation
53
- This line chart illustrates the total square footage of buildings acquired each year, highlighting trends in acquisition sizes over time.
54
  - **Design Choices**:
55
- - A line chart was selected to effectively display changes over time.
56
- - Data points are marked to emphasize individual years.
57
- - The seagreen color provides a calm and clear visual.
58
- - Interactive tooltips offer precise values upon hovering.
59
  - **Potential Improvements**:
60
- - Incorporating filters to view trends for specific agencies or locations.
61
- - Adding a moving average line to smooth out year-to-year fluctuations.
62
  """)
63
 
 
 
 
 
 
64
 
65
- # Visualization 2: Square Footage by Usage Description
66
- st.header("Square Footage by Usage Description")
67
- usage_chart = alt.Chart(data).mark_boxplot().encode(
68
- alt.X('Usage Description:N', title="Usage Description"),
69
- alt.Y('Square Footage:Q', title="Square Footage"),
70
- color='Usage Description:N'
71
  ).properties(
72
  width=700,
73
  height=400,
74
- title="Square Footage by Usage Description"
75
- )
76
- st.altair_chart(usage_chart, use_container_width=True)
 
77
 
78
  st.markdown("""
79
- ### Explanation
80
- This visualization compares the square footage of buildings across various usage descriptions.
81
  - **Design Choices**:
82
- - A boxplot was selected to highlight the distribution of square footage within each usage category.
83
- - Colors were added to distinguish categories visually.
84
- - The plot was scaled to ensure data clarity and eliminate crowding.
 
85
  - **Potential Improvements**:
86
- - Adding a tooltip to show specific statistics (e.g., median, quartiles) for each category.
87
- - Including an interactive filter to explore categories of interest.
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