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