import streamlit as st import csv import base64 # Define the state populations and family sizes state_data = { 'California': {'population': 39538223, 'family_size': 3.3}, 'Texas': {'population': 29145505, 'family_size': 3.4}, 'Florida': {'population': 21538187, 'family_size': 3.0}, 'New York': {'population': 19849399, 'family_size': 3.1}, 'Minnesota': {'population': 5700671, 'family_size': 2.5}, 'Wisconsin': {'population': 5897473, 'family_size': 2.6}, } # Define the state spending data spending_data = { 'California': {'education': 2500, 'healthcare': 3000, 'transportation': 1500}, 'Texas': {'education': 2000, 'healthcare': 2500, 'transportation': 1000}, 'Florida': {'education': 1500, 'healthcare': 2000, 'transportation': 750}, 'New York': {'education': 3000, 'healthcare': 3500, 'transportation': 2000}, 'Minnesota': {'education': 1000, 'healthcare': 1500, 'transportation': 500}, 'Wisconsin': {'education': 1250, 'healthcare': 1750, 'transportation': 750}, } # Define the emoji icons POPULATION_ICON = '๐Ÿ‘ฅ' FAMILY_SIZE_ICON = '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ' EDUCATION_ICON = '๐Ÿซ' HEALTHCARE_ICON = '๐Ÿฅ' TRANSPORTATION_ICON = '๐Ÿš—' def main(): st.title('State Comparison') # Consolidate the state data and spending data into a list of dictionaries state_list = [] for state, data in state_data.items(): state_dict = { 'state': state, 'population': data['population'], 'family_size': data['family_size'], 'education_spending': spending_data[state]['education'], 'healthcare_spending': spending_data[state]['healthcare'], 'transportation_spending': spending_data[state]['transportation'] } state_list.append(state_dict) # Save the data to a CSV file and provide a download link with open('state_data.csv', mode='w', newline='') as file: writer = csv.DictWriter(file, fieldnames=['state', 'population', 'family_size', 'education_spending', 'healthcare_spending', 'transportation_spending']) writer.writeheader() for state in state_list: writer.writerow(state) with open('state_data.csv', mode='rb') as file: b64 = base64.b64encode(file.read()).decode('utf-8') st.markdown(f'Download State Data CSV File', unsafe_allow_html=True) # Display state populations and family sizes st.header('Population and Family Size') for state, data in state_data.items(): st.subheader(f'{POPULATION_ICON} {state}') st.write(f'Population: {data["population"]}') st.write(f'Family Size: {data["family_size"]}') # Display state spending data st.header('State Spending') for state, data in spending_data.items(): st.subheader(state) st.write(f'{EDUCATION_ICON} Education: {data["education"]}') st.write(f'{HEALTHCARE_ICON} Healthcare: {data["healthcare"]}') st.write(f'{TRANSPORTATION_ICON} Transportation: {data["transportation"]}')