Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
|
| 4 |
-
#
|
| 5 |
-
hospitals =
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
def generate_hospital_data():
|
| 4 |
+
# Generate hospital data
|
| 5 |
+
hospitals = {
|
| 6 |
+
"city": ["New York", "Los Angeles", "Chicago", "Houston", "Phoenix"],
|
| 7 |
+
"state": ["NY", "CA", "IL", "TX", "AZ"],
|
| 8 |
+
"bed_count": [1200, 1500, 1100, 1300, 1400],
|
| 9 |
+
}
|
| 10 |
+
df = pd.DataFrame(hospitals)
|
| 11 |
+
return df
|
| 12 |
+
def generate_state_data():
|
| 13 |
+
# Generate state data
|
| 14 |
+
states = {
|
| 15 |
+
"state": ["NY", "CA", "IL", "TX", "AZ"],
|
| 16 |
+
"population": [20000000, 40000000, 13000000, 29000000, 7000000],
|
| 17 |
+
"square_miles": [54556, 163696, 57914, 268596, 113990],
|
| 18 |
+
}
|
| 19 |
+
df = pd.DataFrame(states)
|
| 20 |
+
return df
|
| 21 |
+
def merge_datasets(hospitals_df, states_df):
|
| 22 |
+
# Merge hospital and state data
|
| 23 |
+
merged_df = pd.merge(hospitals_df, states_df, on="state")
|
| 24 |
+
return merged_df
|
| 25 |
+
def calculate_beds_per_capita(merged_df):
|
| 26 |
+
# Calculate beds per capita
|
| 27 |
+
merged_df["beds_per_capita"] = merged_df["bed_count"] / merged_df["population"]
|
| 28 |
+
return merged_df
|
| 29 |
+
def main():
|
| 30 |
+
# Generate data
|
| 31 |
+
hospitals_df = generate_hospital_data()
|
| 32 |
+
states_df = generate_state_data() # Merge datasets
|
| 33 |
+
merged_df = merge_datasets(hospitals_df, states_df) # Calculate beds per capita
|
| 34 |
+
merged_df = calculate_beds_per_capita(merged_df) # Show merged and calculated data
|
| 35 |
+
st.write(merged_df)
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
main()
|