awacke1 commited on
Commit
7a985b7
·
1 Parent(s): 7236b43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +108 -48
app.py CHANGED
@@ -2,64 +2,124 @@ import streamlit as st
2
  import pandas as pd
3
  import altair as alt
4
 
5
- # Load hospital dataset
6
- hospitals_df = pd.read_csv("https://data.medicare.gov/api/views/xubh-q36u/rows.csv?accessType=DOWNLOAD")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- # Filter for the largest hospital in each state
9
- largest_hospitals_df = hospitals_df.loc[hospitals_df.groupby("State")["Hospital overall rating"].idxmax()]
10
-
11
- # Select columns to display
12
- cols_to_display = ["State", "Hospital Name", "City", "Zip Code", "lat", "lng"]
13
-
14
- # Create a Streamlit table to display the largest hospitals
15
- st.table(largest_hospitals_df[cols_to_display])
16
 
17
  # Define chart functions
18
- def stacked_bar_chart():
19
- chart = alt.Chart(largest_hospitals_df).mark_bar().encode(
20
- x=alt.X('State:N'),
21
- y=alt.Y('count():Q', stack="normalize"),
22
- color=alt.Color('Hospital Type:N'),
23
- tooltip=['Hospital Name', 'City', 'Hospital overall rating']
24
- ).properties(
25
- width=700,
26
- height=400,
27
- title='Number of Hospitals by State and Type'
28
- )
29
- text = chart.mark_text(
30
- align='center',
31
- baseline='middle',
32
- dx=0,
33
- dy=5,
34
- color='white'
35
- ).encode(
36
- text=alt.Text('count():Q', format='.1f')
37
- )
38
- st.altair_chart(chart + text)
39
-
40
- def bump_chart():
41
- chart = alt.Chart(largest_hospitals_df).transform_rank(
42
- 'Hospital overall rating',
43
- groupby=['State']
44
- ).mark_line().encode(
45
- x='rank:Q',
46
- y=alt.Y('Hospital Name:N', sort='-x'),
47
- color=alt.Color('State:N'),
48
- tooltip=['City', 'Zip Code', 'Hospital overall rating']
49
  ).properties(
50
  width=700,
51
- height=400,
52
- title='Hospital Rankings by State'
53
  )
54
  st.altair_chart(chart)
55
 
56
  # Define chart buttons
57
  st.sidebar.header('Select a Chart')
58
- chart_options = ['Stacked Bar Chart with Text Overlay', 'Bump Chart']
59
  chart_choice = st.sidebar.selectbox('', chart_options)
60
 
61
  # Call chart functions based on user input
62
- if chart_choice == 'Stacked Bar Chart with Text Overlay':
63
- stacked_bar_chart()
64
- elif chart_choice == 'Bump Chart':
65
- bump_chart()
 
2
  import pandas as pd
3
  import altair as alt
4
 
5
+ # Define list of largest hospitals with latitude and longitude
6
+ largest_hospitals = [
7
+ {
8
+ 'name': 'Florida Hospital Orlando',
9
+ 'city': 'Orlando',
10
+ 'state': 'FL',
11
+ 'zip_code': '32803',
12
+ 'bed_count': 2411,
13
+ 'lat': 28.562229,
14
+ 'lng': -81.362976
15
+ },
16
+ {
17
+ 'name': 'Cleveland Clinic',
18
+ 'city': 'Cleveland',
19
+ 'state': 'OH',
20
+ 'zip_code': '44195',
21
+ 'bed_count': 1730,
22
+ 'lat': 41.501669,
23
+ 'lng': -81.621275
24
+ },
25
+ {
26
+ 'name': 'Mayo Clinic',
27
+ 'city': 'Rochester',
28
+ 'state': 'MN',
29
+ 'zip_code': '55905',
30
+ 'bed_count': 1372,
31
+ 'lat': 44.020634,
32
+ 'lng': -92.463476
33
+ },
34
+ {
35
+ 'name': 'NewYork-Presbyterian Hospital-Columbia and Cornell',
36
+ 'city': 'New York',
37
+ 'state': 'NY',
38
+ 'zip_code': '10032',
39
+ 'bed_count': 2332,
40
+ 'lat': 40.840886,
41
+ 'lng': -73.942184
42
+ },
43
+ {
44
+ 'name': 'UCHealth University of Colorado Hospital',
45
+ 'city': 'Aurora',
46
+ 'state': 'CO',
47
+ 'zip_code': '80045',
48
+ 'bed_count': 672,
49
+ 'lat': 39.742401,
50
+ 'lng': -104.834694
51
+ },
52
+ {
53
+ 'name': 'Houston Methodist Hospital',
54
+ 'city': 'Houston',
55
+ 'state': 'TX',
56
+ 'zip_code': '77030',
57
+ 'bed_count': 1063,
58
+ 'lat': 29.710292,
59
+ 'lng': -95.399262
60
+ },
61
+ {
62
+ 'name': 'Johns Hopkins Hospital',
63
+ 'city': 'Baltimore',
64
+ 'state': 'MD',
65
+ 'zip_code': '21287',
66
+ 'bed_count': 1293,
67
+ 'lat': 39.297082,
68
+ 'lng': -76.590726
69
+ },
70
+ {
71
+ 'name': 'Massachusetts General Hospital',
72
+ 'city': 'Boston',
73
+ 'state': 'MA',
74
+ 'zip_code': '02114',
75
+ 'bed_count': 1032,
76
+ 'lat': 42.363371,
77
+ 'lng': -71.068635
78
+ },
79
+ {
80
+ 'name': 'University of Michigan Hospitals-Michigan Medicine',
81
+ 'city': 'Ann Arbor',
82
+ 'state': 'MI',
83
+ 'zip_code': '48109',
84
+ 'bed_count': 1145,
85
+ 'lat': 42.282531,
86
+ 'lng': -83.728376
87
+ },
88
+ {
89
+ 'name': 'Mount Sinai Hospital',
90
+ 'city': 'New York',
91
+ 'state': 'NY',
92
+ 'zip_code': '10029',
93
+ 'bed_count': 1168,
94
+ 'lat': 40.789866,
95
+ 'lng': -73.952348
96
+ }
97
+ ]
98
 
99
+ # Convert list of largest hospitals to a Pandas DataFrame
100
+ largest_hospitals_df = pd.DataFrame(largest_hospitals)
 
 
 
 
 
 
101
 
102
  # Define chart functions
103
+ def map_chart():
104
+ chart = alt.Chart(largest_hospitals_df).mark_circle().encode(
105
+ longitude='lng:Q',
106
+ latitude='lat:Q',
107
+ size=alt.Size('bed_count:Q', title='Bed Count'),
108
+ color=alt.Color('state:N', legend=alt.Legend(title='State')),
109
+ tooltip=['name', 'bed_count', 'city', 'state']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  ).properties(
111
  width=700,
112
+ height=500,
113
+ title='Location of Largest Hospitals in the US'
114
  )
115
  st.altair_chart(chart)
116
 
117
  # Define chart buttons
118
  st.sidebar.header('Select a Chart')
119
+ chart_options = ['Map Chart']
120
  chart_choice = st.sidebar.selectbox('', chart_options)
121
 
122
  # Call chart functions based on user input
123
+ if chart_choice == 'Map Chart':
124
+ map_chart()
125
+