HW6 / app.py
krisin's picture
Update app.py
350fd8a verified
Raw
History Blame Contribute Delete
3.2 kB
import streamlit as st
import pandas as pd
import altair as alt
# Title
st.title("Chicago Professional Licenses (Fall 2022)")
# Load data
url = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/licenses_fall2022.csv"
df = pd.read_csv(url)
# Clean column names (strip spaces)
df.columns = df.columns.str.strip()
# Show data sample
st.write("Sample of the dataset:")
st.dataframe(df.head())
# Viz 1: Bar chart of licenses by license type
license_type_counts = df['License Type'].value_counts().reset_index()
license_type_counts.columns = ['License Type', 'Count']
chart1 = alt.Chart(license_type_counts).mark_bar().encode(
y=alt.Y('License Type:N', sort='-x', title='License Type'),
x=alt.X('Count:Q', title='Number of Licenses'),
color=alt.Color('Count:Q', scale=alt.Scale(scheme='blues'))
).properties(
width=600,
height=400,
title='Number of Licenses by License Type'
)
st.altair_chart(chart1)
# Viz 2: Bar chart of licenses by zip code
zip_counts = df['Zip'].value_counts().reset_index()
zip_counts.columns = ['Zip Code', 'Count']
chart2 = alt.Chart(zip_counts).mark_bar().encode(
x=alt.X('Zip Code:N', sort='-y', title='Zip Code'),
y=alt.Y('Count:Q', title='Number of Licenses'),
color=alt.Color('Count:Q', scale=alt.Scale(scheme='greens'))
).properties(
width=600,
height=400,
title='Number of Licenses by Zip Code'
)
st.altair_chart(chart2)
# Write-up for Viz 1
st.markdown("""
### Visualization 1: Number of Licenses by License Type
This bar chart displays the distribution of professional licenses by their type. The primary feature that is highlighted is how disproportionately licenses are distributed — with certain categories like Detective Board and Dental dominating the dataset, and others have far fewer licenses.
I chose a horizontal bar chart because many of the license type names are long, and this layout makes them more readable. The color scheme is a blue gradient where darker shades represent higher counts.
If I had more time, I would enhance this visualization by adding interactive filters to let users focus on specific license categories or view only the top N license types, and also group similar professions together for a cleaner presentation.
""")
# Write-up for Viz 2
st.markdown("""
### Visualization 2: Number of Licenses by Zip Code
This vertical bar chart illustrates the number of professional licenses distributed across different zip codes. The key feature is the geographical concentration of licenses, where a small number of zip codes account for the majority of records, while most other zip codes have relatively few.
I selected a vertical bar chart for this visualization because zip codes are inherently ordinal and typically placed along the horizontal axis for clarity. The green gradient color scheme was chosen to differentiate this chart from the first one, and still using a sequential color map to indicate quantity.
If I had more time, I would replace the bar chart with a map-based visualization to better convey the spatial patterns, and include an interactive search or filtering tool for zip codes to help users find specific areas more easily.
""")