awacke1 commited on
Commit
fdb29de
Β·
1 Parent(s): 497db06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -44
app.py CHANGED
@@ -4,27 +4,22 @@ import random
4
  import plotly.graph_objects as go
5
  import plotly.express as px
6
 
7
- url = 'https://www.cms.gov/icd10m/version36-fullcode-cms/fullcode_cms/P0001.zip'
8
- df_icd10 = pd.read_csv(url, sep='\t', compression='zip')
9
- df_icd10 = df_icd10[['MS-DRG', 'MS-DRG Title', 'ICD-10-PCS', 'ICD-10-PCS Description', 'ICD-10-CM Code', 'ICD-10-CM Code Description']]
10
- df_icd10 = df_icd10[df_icd10['MS-DRG Title'].str.contains('Diseases of the Circulatory System', case=False)]
11
-
12
  # Define the states and conditions of interest
13
  states = ["Minnesota", "Florida", "California"]
14
  top_n = 10
15
 
16
  # Define the list dictionary of top 10 health conditions descending by cost, with emojis
17
  health_conditions = [
18
- {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "icd10": ["I20", "I25", "I50"], "spending": 214.3},
19
- {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "icd10": ["S00-T98"], "spending": 198.6},
20
- {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "icd10": ["C00-C96"], "spending": 171.0},
21
- {"condition": "🧠 Mental disorders", "emoji": "🧘", "icd10": ["F00-F99"], "spending": 150.8},
22
- {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "icd10": ["M00-M25", "M40-M54"], "spending": 142.4},
23
- {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "icd10": ["E10-E14"], "spending": 107.4},
24
- {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "icd10": ["J40-J47"], "spending": 91.0},
25
- {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "icd10": ["I10-I15"], "spending": 83.9},
26
- {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "icd10": ["E78"], "spending": 83.9},
27
- {"condition": "🦴 Back problems", "emoji": "🧍", "icd10": ["M40-M54"], "spending": 67.0}
28
  ]
29
 
30
  # Create a DataFrame from the list dictionary
@@ -34,32 +29,28 @@ df_top_conditions = pd.DataFrame(health_conditions)
34
  total_spending = round(df_top_conditions["spending"].sum(), 1)
35
 
36
  # Define the roll function
37
- def roll(icd10):
38
- # Filter the CMS data to include only the given ICD-10 codes
39
- df_filtered = df_icd10[df_icd10['ICD-10-CM Code'].str.contains(icd10, case=False)]
40
- # Group the data by ICD--10-CM Code and sum the spending for each code
41
- df_grouped = df_filtered.groupby(['ICD-10-CM Code', 'ICD-10-CM Code Description']).agg({'spending': 'sum'}).reset_index()
42
- # Sort the data by spending in descending order
43
- df_sorted = df_grouped.sort_values('spending', ascending=False)
44
- # Return the top 3 variants
45
- return df_sorted.head(3)
46
-
47
- #Define the bar chart
48
- fig_bar = go.Figure()
49
-
50
- #Iterate over each health condition and add a bar to the chart
51
- for i, condition in df_top_conditions.iterrows():
52
- icd10 = '|'.join(condition['icd10'])
53
- df_top_variants = roll(icd10)
54
- fig_bar.add_trace(go.Bar(
55
- x=df_top_variants['ICD-10-CM Code Description'],
56
- y=df_top_variants['spending'],
57
- name=condition['condition'],
58
- marker=dict(color=f"rgba{px.colors.qualitative.Plotly[i]}")
59
- ))
60
-
61
- # Customize the layout of the bar chart
62
- fig_bar.update_layout(barmode='group', title=f"Top 3 Variants by Spending for Each Health Condition in {', '.join(states)}", xaxis_title='ICD-10-CM Code Description', yaxis_title='Spending')
63
-
64
- # Display the bar chart in the Streamlit app
65
- st.plotly_chart(fig_bar)
 
4
  import plotly.graph_objects as go
5
  import plotly.express as px
6
 
 
 
 
 
 
7
  # Define the states and conditions of interest
8
  states = ["Minnesota", "Florida", "California"]
9
  top_n = 10
10
 
11
  # Define the list dictionary of top 10 health conditions descending by cost, with emojis
12
  health_conditions = [
13
+ {"condition": "πŸ’” Heart disease", "emoji": "πŸ’—", "spending": 214.3},
14
+ {"condition": "πŸ€• Trauma-related disorders", "emoji": "πŸš‘", "spending": 198.6},
15
+ {"condition": "πŸ¦€ Cancer", "emoji": "πŸŽ—οΈ", "spending": 171.0},
16
+ {"condition": "🧠 Mental disorders", "emoji": "🧘", "spending": 150.8},
17
+ {"condition": "🦴 Osteoarthritis and joint disorders", "emoji": "πŸ₯", "spending": 142.4},
18
+ {"condition": "πŸ’‰ Diabetes", "emoji": "🩸", "spending": 107.4},
19
+ {"condition": "🫁 Chronic obstructive pulmonary disease and asthma", "emoji": "πŸ«€", "spending": 91.0},
20
+ {"condition": "🩺 Hypertension", "emoji": "πŸ’‰", "spending": 83.9},
21
+ {"condition": "πŸ”¬ Hyperlipidemia", "emoji": "πŸ”¬", "spending": 83.9},
22
+ {"condition": "🦴 Back problems", "emoji": "🧍", "spending": 67.0}
23
  ]
24
 
25
  # Create a DataFrame from the list dictionary
 
29
  total_spending = round(df_top_conditions["spending"].sum(), 1)
30
 
31
  # Define the roll function
32
+ def roll():
33
+ # Generate a thousand 10-sided dice rolls for each health condition
34
+ rolls = [random.randint(1, 10) for _ in range(1000)]
35
+ # Calculate the frequency of each variant
36
+ frequencies = [rolls.count(i) for i in range(1, 11)]
37
+ return frequencies
38
+
39
+ # Define the sunburst chart
40
+ fig_sunburst = go.Figure(go.Sunburst(
41
+ labels=df_top_conditions["emoji"] + " " + df_top_conditions["condition"],
42
+ parents=[""] * top_n,
43
+ values=df_top_conditions["spending"],
44
+ maxdepth=2
45
+ ))
46
+
47
+ # Customize the layout of the sunburst chart
48
+ fig_sunburst.update_layout(title=f"Top {top_n} Health Conditions in {', '.join(states)} by Spending (Total: ${total_spending}B)")
49
+
50
+ # Display the sunburst chart and variants per condition in the Streamlit app
51
+ st.plotly_chart(fig_sunburst)
52
+ for index, row in df_top_conditions.iterrows():
53
+ frequencies = roll()
54
+ fig_bar = px.bar(x=[f"Variant {i}" for i in range(1, 11)], y=frequencies[:10], labels={'x': 'Variant', 'y': 'Frequency'})
55
+ fig_bar.update_layout(title=f"Variants of {row['condition']} ({row['emoji']})")
56
+ st.plotly_chart(fig_bar)