Spaces:
Sleeping
Sleeping
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,113 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import altair as alt
|
| 4 |
-
|
| 5 |
-
# Loading the dataset
|
| 6 |
-
url = 'https://github.com/UIUC-iSchool-DataViz/is445_data/raw/main/licenses_fall2022.csv'
|
| 7 |
-
df = pd.read_csv(url)
|
| 8 |
-
|
| 9 |
-
# Dropping unnecessary columns to prevent serialization errors and reduce data size
|
| 10 |
-
df.drop(columns=['Title', 'Prefix', 'Suffix', 'BusinessDBA', '_id', 'Delegated Controlled Substance Schedule', 'Case Number'], inplace=True, errors='ignore')
|
| 11 |
-
|
| 12 |
-
# Converting date columns to datetime format, handling errors
|
| 13 |
-
date_columns = ['Original Issue Date', 'Effective Date', 'Expiration Date', 'LastModifiedDate']
|
| 14 |
-
for col in date_columns:
|
| 15 |
-
df[col] = pd.to_datetime(df[col], errors='coerce')
|
| 16 |
-
|
| 17 |
-
# Converting object columns to category for performance improvement
|
| 18 |
-
for col in df.select_dtypes(include='object').columns:
|
| 19 |
-
df[col] = df[col].astype('category')
|
| 20 |
-
|
| 21 |
-
# Dropping rows with missing values in essential columns to ensure Arrow compatibility
|
| 22 |
-
df.dropna(subset=['License Type', 'License Status', 'Original Issue Date'], inplace=True)
|
| 23 |
-
|
| 24 |
-
# Adding Year columns for visualizations
|
| 25 |
-
df['Original Issue Year'] = df['Original Issue Date'].dt.year
|
| 26 |
-
|
| 27 |
-
# Visualization 1: Bar chart showing licenses by Status
|
| 28 |
-
st.subheader("Licenses by Status")
|
| 29 |
-
category_counts = df['License Status'].value_counts().reset_index()
|
| 30 |
-
category_counts.columns = ['License Status', 'Count']
|
| 31 |
-
|
| 32 |
-
if not category_counts.empty:
|
| 33 |
-
chart1 = alt.Chart(category_counts).mark_bar().encode(
|
| 34 |
-
x=alt.X('License Status', sort='-y', title='License Type'),
|
| 35 |
-
y=alt.Y('Count', title='Number of Licenses', scale=alt.Scale(domain=[0, 100])),
|
| 36 |
-
color=alt.Color('License Status', legend=None)
|
| 37 |
-
).properties(
|
| 38 |
-
width=600,
|
| 39 |
-
height=400,
|
| 40 |
-
title="Number of Licenses by Status"
|
| 41 |
-
)
|
| 42 |
-
st.altair_chart(chart1)
|
| 43 |
-
else:
|
| 44 |
-
st.write("No data available for the 'License Status' plot.")
|
| 45 |
-
|
| 46 |
-
# Write-up for Visualization 1
|
| 47 |
-
st.write("""
|
| 48 |
-
**Licenses by Status**: This bar chart visualizes the distribution of licenses by status, helping to identify the prevalence of each category.
|
| 49 |
-
The use of a bar chart allows for a straightforward comparison between different statuses. Sorting the bars in descending order aids in readability,
|
| 50 |
-
while color differentiation helps make each category distinct. Setting the Y-axis scale to a maximum of 100 highlights categories with smaller counts,
|
| 51 |
-
giving a balanced view of the data distribution. This scale choice emphasizes categories with relatively lower counts, which might otherwise be overshadowed.
|
| 52 |
-
If given more time, interactive features such as filtering by other license attributes would add to the depth of analysis.
|
| 53 |
-
""")
|
| 54 |
-
|
| 55 |
-
# Visualization 2: Line chart showing licenses issued over time
|
| 56 |
-
st.subheader("Licenses Over Time")
|
| 57 |
-
time_data = df.groupby('Original Issue Year').size().reset_index(name='License Count')
|
| 58 |
-
|
| 59 |
-
if not time_data.empty:
|
| 60 |
-
chart2 = alt.Chart(time_data).mark_line().encode(
|
| 61 |
-
x=alt.X('Original Issue Year', title='Year'),
|
| 62 |
-
y=alt.Y('License Count', title='Number of Licenses', scale=alt.Scale(domain=[0, 100])),
|
| 63 |
-
color=alt.value('blue')
|
| 64 |
-
).properties(
|
| 65 |
-
width=600,
|
| 66 |
-
height=400,
|
| 67 |
-
title="Number of Licenses Issued Over Time"
|
| 68 |
-
)
|
| 69 |
-
st.altair_chart(chart2)
|
| 70 |
-
else:
|
| 71 |
-
st.write("No data available for the 'Licenses Over Time' plot.")
|
| 72 |
-
|
| 73 |
-
# Write-up for Visualization 2
|
| 74 |
-
st.write("""
|
| 75 |
-
**Licenses Over Time**: This line chart tracks the trend of licenses issued annually, illustrating changes in licensing activity over time.
|
| 76 |
-
Using a line chart effectively displays year-over-year fluctuations, making it easy to observe trends. The color choice of blue adds consistency and clarity.
|
| 77 |
-
Setting the Y-axis to a maximum scale of 100 allows smaller annual variations to be more visible, offering a clearer picture of subtle changes in license issuance.
|
| 78 |
-
With more development time, analyzing seasonal or monthly trends within each year could yield additional insights, revealing potential cyclical patterns.
|
| 79 |
-
""")
|
| 80 |
-
|
| 81 |
-
# Write-up explaining the thought process for both visualisations
|
| 82 |
-
st.write("""
|
| 83 |
-
**Write-up explaining the thought process for both visualisations:**
|
| 84 |
-
|
| 85 |
-
** 1. Licenses by Status:**
|
| 86 |
-
|
| 87 |
-
Purpose: This bar chart compares the frequency of different license statuses, giving insight into how licenses are categorized. For example, it might show the relative proportion of active versus inactive licenses.
|
| 88 |
-
|
| 89 |
-
Design Choices:
|
| 90 |
-
|
| 91 |
-
Sorting bars in descending order brings the most common categories to the top, allowing for quick comparison.
|
| 92 |
-
|
| 93 |
-
Colors are used for clear category distinction, making the chart visually engaging.
|
| 94 |
-
|
| 95 |
-
A fixed maximum of 100 on the Y-axis balances the focus on both high and low-count categories, helping smaller counts stand out.
|
| 96 |
-
|
| 97 |
-
Future Enhancements: Interactivity, such as the ability to filter by additional fields like specialty or location, could enhance insights further.
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
** 2. Licenses Over Time:**
|
| 101 |
-
|
| 102 |
-
Purpose: This line chart provides a time-based view, revealing trends in license issuance across years. It is especially useful for identifying growth or decline patterns in licensing.
|
| 103 |
-
|
| 104 |
-
Design Choices:
|
| 105 |
-
|
| 106 |
-
The line chart captures year-over-year changes smoothly, helping viewers spot peaks and troughs.
|
| 107 |
-
|
| 108 |
-
Using a single color (blue) maintains simplicity and avoids distractions from the primary focus on the trend.
|
| 109 |
-
|
| 110 |
-
Setting the Y-axis to 100 highlights variations even when counts are low, helping identify periods of slow growth or decline.
|
| 111 |
-
|
| 112 |
-
Future Enhancements: Examining more granular patterns, such as seasonal trends, could add another dimension, revealing factors that might influence licensing activity annually.
|
| 113 |
-
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|