Spaces:
No application file
No application file
| # put streamlit code here as needed | |
| import streamlit as st | |
| import pandas as pd | |
| import altair as alt | |
| st.set_page_config(page_title= "IS 445 Streamlit Homework", layout= "wide") | |
| st.title("Illinois License Records") | |
| licds = "https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/licenses_fall2022.csv" | |
| def licdata(): | |
| df = pd.read_csv(licds) | |
| #fixes date string stuff | |
| df["Original Issue Date"] = pd.to_datetime(df["Original Issue Date"], errors= "coerce") | |
| df["Expiration Date"] = pd.to_datetime(df["Expiration Date"], errors= "coerce") | |
| #changes the cols for plot bc full dates were ugly | |
| df["Issue Year"] = df["Original Issue Date"].dt.year | |
| df["Expiration Year"] = df["Expiration Date"].dt.year | |
| return df | |
| df = licdata() | |
| st.write( | |
| "This app is using the Illinois licenses dataset (https://raw.githubusercontent.com/UIUC-iSchool-DataViz/is445_data/main/licenses_fall2022.csv). " | |
| "The dataset includes cols like: license type, license status, city, county, issue date, expiration date, and discipline.") | |
| st.subheader("License Status by Type") | |
| commonlics = (df["License Type"].value_counts().head(5).index) | |
| commonfltrd = df[df["License Type"].isin(commonlics)].copy() | |
| #interactivity for legend | |
| statuss= alt.selection_point(fields= ["License Status"], bind= "legend") | |
| plot1 = (alt.Chart(commonfltrd).mark_bar().encode( | |
| y= alt.Y("License Type:N", sort= "-x", title= "License Type"), | |
| x= alt.X("count():Q", title= "Number of Records"), | |
| color= alt.Color("License Status:N", title="License Status", scale= alt.Scale(scheme= "tableau20")), | |
| order= alt.Order("License Stats:N", sort= "descending"), | |
| opacity= alt.condition(statuss, alt.value(1), alt.value(0.2)), | |
| tooltip= ["License Type:N", "License Status:N", "count():Q"]).add_params(statuss)) | |
| # .properties(width=800, height=400)) | |
| st.altair_chart(plot1, use_container_width= True) | |
| st.write( | |
| "This first visualization looks into how license records are spread out over the top 5 most common license types, and each bar broken down into the license status. I tried multiple types of plots but settled on a horizontal stacked bar chart primarily due to category names being so long. The horizontal orientation made them easiest to read while still letting me compare the differnt totals. I ended up doing some extra work to sort the bars by the largest categories, and I chose a common color pallet to differentiate between each group. The legend is the interactive aspect, so the viewer can isolate and breakdown any statuses. If I had more time, I would shorten the number of status categories shown or group smaller/redundant ones together so the sections are easier to see. I would also like to order the legend by size but I do not know how to do that.") | |
| st.subheader("Issue Years for Active Licenses") | |
| #had to do some extra stuff here becuase of how i handled the date time before | |
| activels = df[(df["License Status"] == "ACTIVE") & (df["Issue Year"].notna()) & (df["Issue Year"] >= 1950)].copy() | |
| plot2 = (alt.Chart(activels).mark_bar().encode( | |
| #better binning bc of so many years | |
| x= alt.X("Issue Year:O", bin= alt.Bin(step= 5, extent=[1966, 2022]), title= "Year Issued"), | |
| y=alt.Y("count():Q", title="# of Active Licenses"), | |
| tooltip= [alt.Tooltip("Issue Year:Q", bin= alt.Bin(step= 5, extent=[1966, 2022]), title= "Issue Year Range"), | |
| alt.Tooltip("count():Q", title= "# of Active Licenses")])) | |
| st.altair_chart(plot2, use_container_width= True) | |
| st.write("The second visualization looks only at the active licenses and looks at when they were originally issued. They were grouped into five-year bins due to the data set having 56 unique years, since the data ranges from 1966 to 2022 I wanted to reflect that, however altair would not let me set the domain. The binned bar chart made it far easier to identify these trends by zooming out a little, it also makes the increases more stable over time instead of larger spikes and so on, especially in recent years. I also fixed the date times and filtered out any missing values and very early years to keep the focus on the more recent licensing trends. If I had more time, I would want to compare this with other license statuses so I could see how the timing relates to whether a license will remain active or become inactive later over time.") | |
| st.subheader("HW5 Overlap") | |
| st.write("I am not reusing the Building Inventory dataset or the same plots types from Homework #5 nor any of the same code. I chose the Illinois licenses dataset for the streamlit hw here instead, so the dataset, variables, and visual design are going to be quite different to my prior Homework #5 submission mainly becuase I was not a fan of the dataset before.") |