Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
# Define datasets | |
hospital_data = [ | |
{'city': 'New York', 'state': 'NY', 'bed_count': 1500}, | |
{'city': 'Los Angeles', 'state': 'CA', 'bed_count': 2000}, | |
{'city': 'Chicago', 'state': 'IL', 'bed_count': 1200}, | |
{'city': 'Houston', 'state': 'TX', 'bed_count': 1300}, | |
{'city': 'Philadelphia', 'state': 'PA', 'bed_count': 1100} | |
] | |
population_data = [ | |
{'state': 'NY', 'population': 20000000, 'square_miles': 54555}, | |
{'state': 'CA', 'population': 40000000, 'square_miles': 163696}, | |
{'state': 'IL', 'population': 13000000, 'square_miles': 57914}, | |
{'state': 'TX', 'population': 29000000, 'square_miles': 268596}, | |
{'state': 'PA', 'population': 13000000, 'square_miles': 46055} | |
] | |
# Convert datasets to pandas dataframes | |
hospital_df = pd.DataFrame(hospital_data) | |
population_df = pd.DataFrame(population_data) | |
# Merge datasets on 'state' column | |
merged_df = pd.merge(hospital_df, population_df, on='state') | |
# Filter merged dataset to only include hospitals with over 1000 beds | |
filtered_df = merged_df[merged_df['bed_count'] > 1000] | |
# Calculate hospital density as population per hospital bed | |
filtered_df['hospital_density'] = filtered_df['population'] / filtered_df['bed_count'] | |
# Display merged and filtered dataset in Streamlit app | |
st.write(filtered_df) | |