File size: 2,028 Bytes
a3a53d2
 
34929af
a3a53d2
40ed27a
 
a3a53d2
 
40ed27a
e3887ab
40ed27a
 
 
 
 
 
 
 
 
 
e3887ab
 
 
 
 
 
 
a3a53d2
40ed27a
 
 
 
 
 
 
 
 
a3a53d2
40ed27a
a3a53d2
 
e3887ab
a3a53d2
 
 
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
38
39
40
41
42
43
44
45
46
import streamlit as st
import plotly.express as px
import pandas as pd

# Define the states and conditions of interest with emojis
states = ["Minnesota 🌲", "Florida 🌴", "California 🌞"]
top_n = 10

# Define the list dictionary of top 10 health conditions descending by cost with emojis
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 a new field showing the state with the most cases per year for each condition
df_top_conditions['most_cases_state'] = ''
for i, row in df_top_conditions.iterrows():
    condition = row['condition'].split(' ')[0]
    condition_df = pd.read_csv(f'{condition}.csv')
    condition_df = condition_df[condition_df['state'].isin(states)]
    most_cases_state = condition_df.groupby('state')['cases'].sum().idxmax()
    df_top_conditions.at[i, 'most_cases_state'] = f'{most_cases_state} 🏆'

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

# 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)