File size: 1,407 Bytes
d21eb79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import streamlit as st
import plotly.express as px
import pandas as pd

# Define the states and conditions of interest
states = ["Minnesota", "Florida", "California"]
top_n = 10

# Define the list dictionary of top 10 health conditions descending by cost
health_conditions = [
    {"condition": "Heart disease", "spending": 214.3},
    {"condition": "Trauma-related disorders", "spending": 198.6},
    {"condition": "Cancer", "spending": 171.0},
    {"condition": "Mental disorders", "spending": 150.8},
    {"condition": "Osteoarthritis and joint disorders", "spending": 142.4},
    {"condition": "Diabetes", "spending": 107.4},
    {"condition": "Chronic obstructive pulmonary disease and asthma", "spending": 91.0},
    {"condition": "Hypertension", "spending": 83.9},
    {"condition": "Hyperlipidemia", "spending": 83.9},
    {"condition": "Back problems", "spending": 67.0}
]

# Total the spending values
total_spending = sum([hc["spending"] for hc in health_conditions])

# Create a DataFrame from the list dictionary
df_top_conditions = pd.DataFrame(health_conditions)

# Create the treemap graph using Plotly Express
fig = px.treemap(df_top_conditions, path=["condition"], values="spending")

# Set the title of the graph
fig.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")

# Display the graph in Streamlit
st.plotly_chart(fig)