GeekTony/streamlit-Data-Synthesis-Example
0
1import streamlit as st2import pandas as pd3 4# Define datasets5hospital_data = [6 {'city': 'New York', 'state': 'NY', 'bed_count': 1500},7 {'city': 'Los Angeles', 'state': 'CA', 'bed_count': 2000},8 {'city': 'Chicago', 'state': 'IL', 'bed_count': 1200},9 {'city': 'Houston', 'state': 'TX', 'bed_count': 1300},10 {'city': 'Philadelphia', 'state': 'PA', 'bed_count': 1100}11]12 13population_data = [14 {'state': 'NY', 'population': 20000000, 'square_miles': 54555},15 {'state': 'CA', 'population': 40000000, 'square_miles': 163696},16 {'state': 'IL', 'population': 13000000, 'square_miles': 57914},17 {'state': 'TX', 'population': 29000000, 'square_miles': 268596},18 {'state': 'PA', 'population': 13000000, 'square_miles': 46055}19]20 21# Convert datasets to pandas dataframes22hospital_df = pd.DataFrame(hospital_data)23population_df = pd.DataFrame(population_data)24 25# Merge datasets on 'state' column26merged_df = pd.merge(hospital_df, population_df, on='state')27 28# Filter merged dataset to only include hospitals with over 1000 beds29filtered_df = merged_df[merged_df['bed_count'] > 1000]30 31# Calculate hospital density as population per hospital bed32filtered_df['hospital_density'] = filtered_df['population'] / filtered_df['bed_count']33 34# Display merged and filtered dataset in Streamlit app35st.write(filtered_df)36 