Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,22 +2,22 @@ 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
|
10 |
health_conditions = [
|
11 |
-
{"condition": "Heart disease", "spending": 214.3},
|
12 |
-
{"condition": "Trauma-related disorders", "spending": 198.6},
|
13 |
-
{"condition": "Cancer", "spending": 171.0},
|
14 |
-
{"condition": "Mental disorders", "spending": 150.8},
|
15 |
-
{"condition": "Osteoarthritis and joint disorders", "spending": 142.4},
|
16 |
-
{"condition": "Diabetes", "spending": 107.4},
|
17 |
-
{"condition": "Chronic obstructive pulmonary disease and asthma", "spending": 91.0},
|
18 |
-
{"condition": "Hypertension", "spending": 83.9},
|
19 |
-
{"condition": "Hyperlipidemia", "spending": 83.9},
|
20 |
-
{"condition": "Back problems", "spending": 67.0}
|
21 |
]
|
22 |
|
23 |
# Total the spending values
|
@@ -26,8 +26,17 @@ total_spending = sum([hc["spending"] for hc in health_conditions])
|
|
26 |
# Create a DataFrame from the list dictionary
|
27 |
df_top_conditions = pd.DataFrame(health_conditions)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
# Create the treemap graph using Plotly Express
|
30 |
-
fig = px.treemap(df_top_conditions, path=["condition"], values="spending")
|
31 |
|
32 |
# Set the title of the graph
|
33 |
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|
|
|
2 |
import plotly.express as px
|
3 |
import pandas as pd
|
4 |
|
5 |
+
# Define the states and conditions of interest with emojis
|
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
|
10 |
health_conditions = [
|
11 |
+
{"condition": "Heart disease ❤️", "spending": 214.3},
|
12 |
+
{"condition": "Trauma-related disorders 🤕", "spending": 198.6},
|
13 |
+
{"condition": "Cancer 🦀", "spending": 171.0},
|
14 |
+
{"condition": "Mental disorders 🧠", "spending": 150.8},
|
15 |
+
{"condition": "Osteoarthritis and joint disorders 🦴", "spending": 142.4},
|
16 |
+
{"condition": "Diabetes 🍬", "spending": 107.4},
|
17 |
+
{"condition": "Chronic obstructive pulmonary disease and asthma 🫁", "spending": 91.0},
|
18 |
+
{"condition": "Hypertension 🩺", "spending": 83.9},
|
19 |
+
{"condition": "Hyperlipidemia 🍔", "spending": 83.9},
|
20 |
+
{"condition": "Back problems 👨⚕️", "spending": 67.0}
|
21 |
]
|
22 |
|
23 |
# Total the spending values
|
|
|
26 |
# Create a DataFrame from the list dictionary
|
27 |
df_top_conditions = pd.DataFrame(health_conditions)
|
28 |
|
29 |
+
# Create a new field showing the state with the most cases per year for each condition
|
30 |
+
df_top_conditions['most_cases_state'] = ''
|
31 |
+
for i, row in df_top_conditions.iterrows():
|
32 |
+
condition = row['condition'].split(' ')[0]
|
33 |
+
condition_df = pd.read_csv(f'{condition}.csv')
|
34 |
+
condition_df = condition_df[condition_df['state'].isin(states)]
|
35 |
+
most_cases_state = condition_df.groupby('state')['cases'].sum().idxmax()
|
36 |
+
df_top_conditions.at[i, 'most_cases_state'] = f'{most_cases_state} 🏆'
|
37 |
+
|
38 |
# Create the treemap graph using Plotly Express
|
39 |
+
fig = px.treemap(df_top_conditions, path=["condition"], values="spending", color='most_cases_state')
|
40 |
|
41 |
# Set the title of the graph
|
42 |
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
|