mdidwan2 commited on
Commit
89b5a32
1 Parent(s): 59ae744

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -30
app.py CHANGED
@@ -1,31 +1,37 @@
1
  import streamlit as st
2
- import pandas as pd
3
-
4
- # Define two example datasets
5
- hospitals = [
6
- {'City': 'New York', 'State': 'NY', 'Beds': 2000},
7
- {'City': 'Los Angeles', 'State': 'CA', 'Beds': 1500},
8
- {'City': 'Chicago', 'State': 'IL', 'Beds': 1200},
9
- {'City': 'Houston', 'State': 'TX', 'Beds': 1800},
10
- {'City': 'Phoenix', 'State': 'AZ', 'Beds': 1300}
11
- ]
12
-
13
- populations = [
14
- {'State': 'NY', 'Population': 19530000, 'SquareMiles': 54555},
15
- {'State': 'CA', 'Population': 39540000, 'SquareMiles': 163696},
16
- {'State': 'IL', 'Population': 12670000, 'SquareMiles': 57914},
17
- {'State': 'TX', 'Population': 29150000, 'SquareMiles': 268596},
18
- {'State': 'AZ', 'Population': 7279000, 'SquareMiles': 113990}
19
- ]
20
-
21
- # Merge the datasets based on the state column
22
- df = pd.merge(pd.DataFrame(hospitals), pd.DataFrame(populations), on='State')
23
-
24
- # Filter the merged dataset to include only hospitals with over 1000 beds
25
- df = df[df['Beds'] > 1000]
26
-
27
- # Calculate the number of beds per square mile for each state
28
- df['BedsPerSquareMile'] = df['Beds'] / df['SquareMiles']
29
-
30
- # Display the resulting dataframe in Streamlit
31
- st.write(df)
 
 
 
 
 
 
 
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()