Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import altair as alt | |
| # Title and Introduction | |
| st.title("Building Inventory Analysis") | |
| st.markdown(""" | |
| This application provides insights into the building inventory dataset through two visualizations: | |
| 1. **Building Count by County**: Displays the number of buildings in each county. | |
| 2. **Year-wise Construction of Buildings**: Shows the count of buildings constructed each year. | |
| Each visualization is accompanied by a brief explanation, including design choices and potential improvements. | |
| """) | |
| # Load Dataset | |
| def load_data(): | |
| url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv" | |
| return pd.read_csv(url) | |
| data = load_data() | |
| # Data Preprocessing | |
| # Ensure 'Year Constructed' is numeric | |
| data['Year Constructed'] = pd.to_numeric(data['Year Constructed'], errors='coerce') | |
| # Visualization 1: Building Count by County | |
| st.header("1. Building Count by County") | |
| county_count = data['County'].value_counts().reset_index() | |
| county_count.columns = ['County', 'Building Count'] | |
| county_chart = alt.Chart(county_count).mark_bar(color='teal').encode( | |
| alt.X('Building Count:Q', title='Number of Buildings'), | |
| alt.Y('County:N', sort='-x', title='County') | |
| ).properties( | |
| width=700, | |
| height=400, | |
| title='Number of Buildings per County' | |
| ) | |
| st.altair_chart(county_chart, use_container_width=True) | |
| st.markdown(""" | |
| **Explanation**: | |
| This bar chart illustrates the number of buildings in each county, highlighting areas with higher concentrations of government buildings. | |
| - **Design Choices**: | |
| - A horizontal bar chart is used to accommodate long county names and facilitate easy comparison. | |
| - Counties are sorted in descending order based on building count to emphasize those with the most buildings. | |
| - The teal color provides a calm and professional appearance. | |
| - **Potential Improvements**: | |
| - Create grouped bar charts to compare building counts by county across different years. | |
| - Add a map visualization to provide spatial context to the data. | |
| """) | |
| # Visualization 2: Year-wise Construction of Buildings | |
| st.header("2. Year-wise Construction of Buildings") | |
| # Filter out rows where 'Year Constructed' is 0 or NaN | |
| data_filtered = data[(data['Year Constructed'] > 0) & (~data['Year Constructed'].isna())] | |
| # Group by 'Year Constructed' and count the number of buildings | |
| yearly_construction = data_filtered['Year Constructed'].value_counts().reset_index() | |
| yearly_construction.columns = ['Year Constructed', 'Building Count'] | |
| yearly_construction = yearly_construction.sort_values('Year Constructed') | |
| year_chart = alt.Chart(yearly_construction).mark_line(point=True, color='orange').encode( | |
| alt.X('Year Constructed:Q', title='Year Constructed'), | |
| alt.Y('Building Count:Q', title='Number of Buildings') | |
| ).properties( | |
| width=700, | |
| height=400, | |
| title='Number of Buildings Constructed Over Time' | |
| ) | |
| st.altair_chart(year_chart, use_container_width=True) | |
| st.markdown(""" | |
| **Explanation**: | |
| This line chart displays the number of buildings constructed each year, revealing trends and periods of increased construction activity. | |
| - **Design Choices**: | |
| - A line chart effectively shows changes over time and highlights trends. | |
| - Data points are marked to emphasize individual years. | |
| - The orange color draws attention to the trend line. | |
| - **Potential Improvements**: | |
| - Overlay a trendline to highlight long-term construction patterns while reducing the effect of year-to-year fluctuations. | |
| - Allow users to filter the data by building type or agency to explore specific trends. | |
| """) | |
| # Footer | |
| st.markdown(""" | |
| --- | |
| **Data Source**: [Building Inventory Dataset](https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/building_inventory.csv) | |
| **Author**: Maanas Agrawal | |
| """) | |