Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,90 +2,34 @@ import streamlit as st
|
|
2 |
import plotly.express as px
|
3 |
import pandas as pd
|
4 |
|
5 |
-
# Define the states and conditions of interest
|
6 |
states = ["Minnesota 🌲", "Florida 🌴", "California 🌞"]
|
7 |
top_n = 10
|
8 |
|
9 |
-
# Define the list dictionary of top 10 health conditions descending by cost with emojis and Wikipedia links
|
10 |
health_conditions = [
|
11 |
-
{
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
},
|
16 |
-
{
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
}
|
21 |
-
{
|
22 |
-
"condition": "Cancer 🦀",
|
23 |
-
"spending": 171.0,
|
24 |
-
"definition": "Cancer is a disease where your body's cells grow out of control. It can cause lumps or tumors and make you feel sick. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Cancer)."
|
25 |
-
},
|
26 |
-
{
|
27 |
-
"condition": "Mental disorders 🧠",
|
28 |
-
"spending": 150.8,
|
29 |
-
"definition": "Mental disorders are conditions that affect your mood, behavior, or thinking. They can make it hard to function normally. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Mental_disorder)."
|
30 |
-
},
|
31 |
-
{
|
32 |
-
"condition": "Osteoarthritis and joint disorders 🦴",
|
33 |
-
"spending": 142.4,
|
34 |
-
"definition": "Osteoarthritis and joint disorders are conditions that can cause pain and stiffness in your joints. They often happen as you get older. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Osteoarthritis)."
|
35 |
-
},
|
36 |
-
{
|
37 |
-
"condition": "Diabetes 🍬",
|
38 |
-
"spending": 107.4,
|
39 |
-
"definition": "Diabetes is a condition where your body has trouble processing sugar. It can cause high blood sugar levels and make you feel sick. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Diabetes)."
|
40 |
-
},
|
41 |
-
{
|
42 |
-
"condition": "Chronic obstructive pulmonary disease and asthma 🫁",
|
43 |
-
"spending": 91.0,
|
44 |
-
"definition": "Chronic obstructive pulmonary disease (COPD) and asthma are conditions that can make it hard to breathe. They can cause coughing, wheezing, and other symptoms. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Chronic_obstructive_pulmonary_disease)."
|
45 |
-
},
|
46 |
-
{
|
47 |
-
"condition": "Hypertension 🩺",
|
48 |
-
"spending": 83.9,
|
49 |
-
"definition": "Hypertension is another word for high blood pressure. It can put you at risk for heart disease and other health problems. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Hypertension).
|
50 |
-
},
|
51 |
-
{
|
52 |
-
"condition": "Hyperlipidemia 🍔",
|
53 |
-
"spending": 83.9,
|
54 |
-
"definition": "Hyperlipidemia is a condition where you have high levels of fat in your blood. It can put you at risk for heart disease and other health problems. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Hyperlipidemia)."
|
55 |
-
},
|
56 |
-
{
|
57 |
-
"condition": "Back problems 👨⚕️",
|
58 |
-
"spending": 67.0,
|
59 |
-
"definition": "Back problems can cause pain and stiffness in your back. They can be caused by a variety of factors, like poor posture or injuries. Learn more at [Wikipedia](https://en.wikipedia.org/wiki/Back_pain)."
|
60 |
-
}
|
61 |
]
|
62 |
|
63 |
-
#Total the spending values
|
64 |
total_spending = sum([hc["spending"] for hc in health_conditions])
|
65 |
|
66 |
-
#Create a DataFrame from the list dictionary
|
67 |
df_top_conditions = pd.DataFrame(health_conditions)
|
68 |
|
69 |
-
#Create
|
70 |
-
df_top_conditions[
|
71 |
-
for i, row in df_top_conditions.iterrows():
|
72 |
-
condition = row['condition'].split(' ')[0]
|
73 |
-
condition_df = pd.read_csv(f'{condition}.csv')
|
74 |
-
condition_df = condition_df[condition_df['state'].isin(states)]
|
75 |
-
most_cases_state = condition_df.groupby('state')['cases'].sum().idxmax()
|
76 |
-
df_top_conditions.at[i, 'most_cases_state'] = f'{most_cases_state} 🏆'
|
77 |
|
78 |
-
#
|
79 |
-
fig = px.treemap(df_top_conditions, path=["condition"], values="spending", color='most_cases_state')
|
80 |
-
|
81 |
-
#Set the title of the graph
|
82 |
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
83 |
|
84 |
-
#Display the graph in Streamlit
|
85 |
st.plotly_chart(fig)
|
86 |
-
|
87 |
-
#Display definitions of each condition
|
88 |
-
st.markdown("## Condition Definitions")
|
89 |
-
for hc in health_conditions:
|
90 |
-
st.markdown(f"### {hc['condition']}")
|
91 |
-
st.markdown(hc['definition'])
|
|
|
2 |
import plotly.express as px
|
3 |
import pandas as pd
|
4 |
|
5 |
+
# Define the states and conditions of interest
|
6 |
states = ["Minnesota 🌲", "Florida 🌴", "California 🌞"]
|
7 |
top_n = 10
|
8 |
|
|
|
9 |
health_conditions = [
|
10 |
+
{"condition": "Heart disease ❤️", "spending": 214.3},
|
11 |
+
{"condition": "Trauma-related disorders 🤕", "spending": 198.6},
|
12 |
+
{"condition": "Cancer 🦀", "spending": 171.0},
|
13 |
+
{"condition": "Mental disorders 🧠", "spending": 150.8},
|
14 |
+
{"condition": "Osteoarthritis and joint disorders 🦴", "spending": 142.4},
|
15 |
+
{"condition": "Diabetes 🍬", "spending": 107.4},
|
16 |
+
{"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0},
|
17 |
+
{"condition": "Hypertension 🩺", "spending": 83.9},
|
18 |
+
{"condition": "Hyperlipidemia 🍔", "spending": 83.9},
|
19 |
+
{"condition": "Back problems 👨⚕️", "spending": 67.0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
]
|
21 |
|
22 |
+
# Total the spending values
|
23 |
total_spending = sum([hc["spending"] for hc in health_conditions])
|
24 |
|
25 |
+
# Create a DataFrame from the list dictionary
|
26 |
df_top_conditions = pd.DataFrame(health_conditions)
|
27 |
|
28 |
+
# Create the treemap graph using Plotly Express
|
29 |
+
fig = px.treemap(df_top_conditions, path=["condition"], values="spending")
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
# Set the title of the graph
|
|
|
|
|
|
|
32 |
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
33 |
|
34 |
+
# Display the graph in Streamlit
|
35 |
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|