awacke1 commited on
Commit
144723f
·
1 Parent(s): 4ab3c1e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -11
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import streamlit as st
 
2
 
3
  # Define the state populations and family sizes
4
  state_data = {
@@ -29,22 +30,35 @@ TRANSPORTATION_ICON = '🚗'
29
 
30
  def main():
31
  st.title('State Comparison')
32
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # Display state populations and family sizes
34
  st.header('Population and Family Size')
35
  for state, data in state_data.items():
36
  st.subheader(f'{POPULATION_ICON} {state}')
37
  st.write(f'Population: {data["population"]}')
38
  st.write(f'Family Size: {data["family_size"]}')
39
-
40
  # Display state spending data
41
  st.header('State Spending')
42
- for state, data in spending_data.items():
43
- st.subheader(state)
44
- st.write(f'{EDUCATION_ICON} Education: {data["education"]}')
45
- st.write(f'{HEALTHCARE_ICON} Healthcare: {data["healthcare"]}')
46
- st.write(f'{TRANSPORTATION_ICON} Transportation: {data["transportation"]}')
47
-
48
-
49
- if __name__ == '__main__':
50
- main()
 
1
  import streamlit as st
2
+ import csv
3
 
4
  # Define the state populations and family sizes
5
  state_data = {
 
30
 
31
  def main():
32
  st.title('State Comparison')
33
+
34
+ # Consolidate the state data and spending data into a list of dictionaries
35
+ state_list = []
36
+ for state, data in state_data.items():
37
+ state_dict = {
38
+ 'state': state,
39
+ 'population': data['population'],
40
+ 'family_size': data['family_size'],
41
+ 'education_spending': spending_data[state]['education'],
42
+ 'healthcare_spending': spending_data[state]['healthcare'],
43
+ 'transportation_spending': spending_data[state]['transportation']
44
+ }
45
+ state_list.append(state_dict)
46
+
47
+ # Save the data to a CSV file and provide a download link
48
+ with open('state_data.csv', mode='w', newline='') as file:
49
+ writer = csv.DictWriter(file, fieldnames=['state', 'population', 'family_size', 'education_spending', 'healthcare_spending', 'transportation_spending'])
50
+ writer.writeheader()
51
+ for state in state_list:
52
+ writer.writerow(state)
53
+ st.markdown(f'<a href="data:file/csv;base64,{b64}" download="state_data.csv">Download State Data CSV File</a>', unsafe_allow_html=True)
54
+
55
  # Display state populations and family sizes
56
  st.header('Population and Family Size')
57
  for state, data in state_data.items():
58
  st.subheader(f'{POPULATION_ICON} {state}')
59
  st.write(f'Population: {data["population"]}')
60
  st.write(f'Family Size: {data["family_size"]}')
61
+
62
  # Display state spending data
63
  st.header('State Spending')
64
+ for state