Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
def generate_hospital_data(): | |
# Generate hospital data | |
hospitals = { | |
"city": ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"], | |
"state": ["NY", "CA", "IL", "TX", "AZ"], | |
"bed_count": [1200, 1500, 1100, 1300, 1400], | |
} | |
df = pd.DataFrame(hospitals) | |
return df | |
def generate_state_data(): | |
# Generate state data | |
states = { | |
"state": ["NY", "CA", "IL", "TX", "AZ"], | |
"population": [20000000, 40000000, 13000000, 29000000, 7000000], | |
"square_miles": [54556, 163696, 57914, 268596, 113990], | |
} | |
df = pd.DataFrame(states) | |
return df | |
def merge_datasets(hospitals_df, states_df): | |
# Merge hospital and state data | |
merged_df = pd.merge(hospitals_df, states_df, on="state") | |
return merged_df | |
def calculate_beds_per_capita(merged_df): | |
# Calculate beds per capita | |
merged_df["beds_per_capita"] = merged_df["bed_count"] / merged_df["population"] | |
return merged_df | |
def main(): | |
# Generate data | |
hospitals_df = generate_hospital_data() | |
states_df = generate_state_data() # Merge datasets | |
merged_df = merge_datasets(hospitals_df, states_df) # Calculate beds per capita | |
merged_df = calculate_beds_per_capita(merged_df) # Show merged and calculated data | |
st.write(merged_df) | |
if __name__ == "__main__": | |
main() |