Biswa13/Streamlit-Data-Synthesis-Example
0
1import streamlit as st2import pandas as pd3 4# Dataset 1: List of Hospitals that are over 1000 bed count by city and state5hospitals = [6 {'City': 'New York', 'State': 'NY', 'Hospital Name': 'New York-Presbyterian Hospital', 'Bed Count': 2446},7 {'City': 'Houston', 'State': 'TX', 'Hospital Name': 'Memorial Hermann-Texas Medical Center', 'Bed Count': 2048},8 {'City': 'Philadelphia', 'State': 'PA', 'Hospital Name': 'Hospital of the University of Pennsylvania', 'Bed Count': 1875},9 {'City': 'Los Angeles', 'State': 'CA', 'Hospital Name': 'Cedars-Sinai Medical Center', 'Bed Count': 1434},10 {'City': 'Boston', 'State': 'MA', 'Hospital Name': 'Massachusetts General Hospital', 'Bed Count': 1051},11]12 13# Dataset 2: State population size and square miles14population = [15 {'State': 'CA', 'Population': 39538223, 'Square Miles': 163696},16 {'State': 'TX', 'Population': 29145505, 'Square Miles': 268596},17 {'State': 'NY', 'Population': 20215751, 'Square Miles': 54555},18 {'State': 'FL', 'Population': 21538187, 'Square Miles': 65755},19 {'State': 'PA', 'Population': 13002700, 'Square Miles': 46054},20]21 22# Convert the dictionaries into pandas dataframes23hospitals_df = pd.DataFrame(hospitals)24population_df = pd.DataFrame(population)25 26# Merge the two dataframes using 'State' as the key27merged_df = pd.merge(hospitals_df, population_df, on='State')28 29# Join the 'City' and 'State' columns into a single column30merged_df['City_State'] = merged_df['City'] + ', ' + merged_df['State']31 32# Calculate the number of hospital beds per 10,000 people in each city-state33merged_df['Beds per 10K People'] = (merged_df['Bed Count'] / merged_df['Population']) * 1000034 35# Display the final merged dataframe36st.write(merged_df)37 