-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathsolution_app.py
More file actions
39 lines (34 loc) · 1.07 KB
/
solution_app.py
File metadata and controls
39 lines (34 loc) · 1.07 KB
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
import streamlit as st
import pandas as pd
import plotly.express as px
df = pd.read_csv("state_data.csv")
st.header("US State Demographics")
# Let user select which state and demographic to graph
state = st.selectbox("State:", df["State"].unique())
demographic = st.selectbox(
"Demographic:", ["Total Population", "Median Household Income"]
)
graph_tab, table_tab = st.tabs(["📈 Graphs", "🔍 Table"])
with graph_tab:
# Create the graph the user requested
df_state = df[df["State"] == state]
if demographic == "Total Population":
fig = px.line(
df_state,
x="Year",
y="Total Population",
title=f"Total Population of {state}",
)
elif demographic == "Median Household Income":
fig = px.line(
df_state,
x="Year",
y="Median Household Income",
title=f"Median Household Income of {state}",
)
else:
raise ValueError("Unknown demographic!")
st.plotly_chart(fig)
with table_tab:
# Render the entire dataframe
st.dataframe(df)