Spaces:
Runtime error
Runtime error
import streamlit as st | |
import plotly.express as px | |
import pandas as pd | |
# Load the data | |
df = pd.read_csv("health_conditions_data.csv") | |
# Define the states and conditions of interest | |
states = ["Minnesota", "Florida", "California"] | |
top_n = 10 | |
# Filter the data by the selected states and get the top n conditions | |
df_filtered = df[df["state"].isin(states)] | |
df_top_conditions = df_filtered.groupby("condition")["count"].sum().nlargest(top_n) | |
# Create the treemap graph using Plotly Express | |
fig = px.treemap(df_top_conditions, path=["condition"], values="count") | |
# Set the title of the graph | |
fig.update_layout(title="Top 10 Health Conditions in {} by Count".format(", ".join(states))) | |
# Display the graph in Streamlit | |
st.plotly_chart(fig) | |