msa17 commited on
Commit
0e82be3
·
verified ·
1 Parent(s): 9de66d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -14
app.py CHANGED
@@ -23,30 +23,45 @@ data = load_data()
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
- # Visualization 1: Distribution of Buildings by Year Acquired
27
- st.header("Distribution of Buildings by Year Acquired")
28
- year_acquired_chart = alt.Chart(data).mark_bar(color='steelblue').encode(
29
- alt.X('Year Acquired:Q', bin=alt.Bin(maxbins=20), title="Year Acquired"),
30
- alt.Y('count():Q', title="Number of Buildings")
 
 
 
 
 
 
 
 
 
 
 
 
31
  ).properties(
32
  width=700,
33
  height=400,
34
- title="Distribution of Buildings by Year Acquired"
35
- )
36
- st.altair_chart(year_acquired_chart, use_container_width=True)
 
37
 
38
  st.markdown("""
39
  ### Explanation
40
- This visualization highlights the distribution of buildings based on the year they were acquired.
41
  - **Design Choices**:
42
- - A bar chart was chosen for clarity, with years grouped into bins for better aggregation.
43
- - The steel blue color provides a neutral tone and avoids distraction.
44
- - Axis labels and titles were carefully chosen for readability.
 
45
  - **Potential Improvements**:
46
- - If more time was available, I would add an interactive filter to explore specific years.
47
- - It would also be useful to compare acquisition trends by agency or location.
48
  """)
49
 
 
50
  # Visualization 2: Square Footage by Usage Description
51
  st.header("Square Footage by Usage Description")
52
  usage_chart = alt.Chart(data).mark_boxplot().encode(
 
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(