Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
# Define two example datasets | |
hospitals = [ | |
{'City': 'New York', 'State': 'NY', 'Beds': 2000}, | |
{'City': 'Los Angeles', 'State': 'CA', 'Beds': 1500}, | |
{'City': 'Chicago', 'State': 'IL', 'Beds': 1200}, | |
{'City': 'Houston', 'State': 'TX', 'Beds': 1800}, | |
{'City': 'Phoenix', 'State': 'AZ', 'Beds': 1300} | |
] | |
populations = [ | |
{'State': 'NY', 'Population': 19530000, 'SquareMiles': 54555}, | |
{'State': 'CA', 'Population': 39540000, 'SquareMiles': 163696}, | |
{'State': 'IL', 'Population': 12670000, 'SquareMiles': 57914}, | |
{'State': 'TX', 'Population': 29150000, 'SquareMiles': 268596}, | |
{'State': 'AZ', 'Population': 7279000, 'SquareMiles': 113990} | |
] | |
# Merge the datasets based on the state column | |
df = pd.merge(pd.DataFrame(hospitals), pd.DataFrame(populations), on='State') | |
# Filter the merged dataset to include only hospitals with over 1000 beds | |
df = df[df['Beds'] > 1000] | |
# Calculate the number of beds per square mile for each state | |
df['BedsPerSquareMile'] = df['Beds'] / df['SquareMiles'] | |
# Display the resulting dataframe in Streamlit | |
st.write(df) | |