ralate2 commited on
Commit
0909a2e
·
verified ·
1 Parent(s): 54b7778

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -27
app.py CHANGED
@@ -28,22 +28,35 @@ df['Last Modified Date Year'] = df['LastModifiedDate'].dt.year
28
  for col in df.select_dtypes(include='object').columns:
29
  df[col] = df[col].astype('category')
30
 
 
 
 
 
31
  # Visualization 1: Bar chart of licenses by type
32
  st.subheader("Licenses by Type")
33
 
 
34
  category_counts = df['License Type'].value_counts().reset_index()
35
  category_counts.columns = ['License Type', 'Count']
36
 
37
- chart1 = alt.Chart(category_counts).mark_bar().encode(
38
- x=alt.X('License Type', sort='-y', title='License Type'),
39
- y=alt.Y('Count', title='Number of Licenses'),
40
- color=alt.Color('License Type', legend=None)
41
- ).properties(
42
- width=600,
43
- height=400,
44
- title="Number of Licenses by Type"
45
- )
46
- st.altair_chart(chart1)
 
 
 
 
 
 
 
 
47
 
48
  # Write-up for Visualization 1
49
  st.write("""
@@ -56,24 +69,27 @@ If I had more time, I might add interactivity to allow users to filter by other
56
  # Visualization 2: Line chart showing licenses issued over time
57
  st.subheader("Licenses Over Time")
58
 
59
- # Ensure there is no missing data for 'Original Issue Year'
60
- if df['Original Issue Year'].isnull().sum() == 0:
61
- time_data = df.groupby('Original Issue Year').size().reset_index(name='License Count')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  else:
63
- time_data = df.groupby('Original Issue Year').size().reset_index(name='License Count')
64
-
65
- time_data.columns = ['Year', 'License Count']
66
-
67
- chart2 = alt.Chart(time_data).mark_line().encode(
68
- x=alt.X('Year', title='Year'),
69
- y=alt.Y('License Count', title='Number of Licenses'),
70
- color=alt.value('blue')
71
- ).properties(
72
- width=600,
73
- height=400,
74
- title="Number of Licenses Issued Over Time"
75
- )
76
- st.altair_chart(chart2)
77
 
78
  # Write-up for Visualization 2
79
  st.write("""
 
28
  for col in df.select_dtypes(include='object').columns:
29
  df[col] = df[col].astype('category')
30
 
31
+ # Debug: Check the data after preprocessing
32
+ st.write("Data after preprocessing:")
33
+ st.write(df.head()) # Check the first few rows
34
+
35
  # Visualization 1: Bar chart of licenses by type
36
  st.subheader("Licenses by Type")
37
 
38
+ # Group data by License Type
39
  category_counts = df['License Type'].value_counts().reset_index()
40
  category_counts.columns = ['License Type', 'Count']
41
 
42
+ # Debug: Check the grouped data for the first chart
43
+ st.write("Grouped data for licenses by type:")
44
+ st.write(category_counts.head()) # Check if data is available for plotting
45
+
46
+ # Ensure category_counts is not empty before plotting
47
+ if not category_counts.empty:
48
+ chart1 = alt.Chart(category_counts).mark_bar().encode(
49
+ x=alt.X('License Type', sort='-y', title='License Type'),
50
+ y=alt.Y('Count', title='Number of Licenses'),
51
+ color=alt.Color('License Type', legend=None)
52
+ ).properties(
53
+ width=600,
54
+ height=400,
55
+ title="Number of Licenses by Type"
56
+ )
57
+ st.altair_chart(chart1)
58
+ else:
59
+ st.write("No data available for the 'License Type' plot.")
60
 
61
  # Write-up for Visualization 1
62
  st.write("""
 
69
  # Visualization 2: Line chart showing licenses issued over time
70
  st.subheader("Licenses Over Time")
71
 
72
+ # Group data by Original Issue Year
73
+ time_data = df.groupby('Original Issue Year').size().reset_index(name='License Count')
74
+
75
+ # Debug: Check the grouped data for the second chart
76
+ st.write("Grouped data for licenses over time:")
77
+ st.write(time_data.head()) # Check if data is available for plotting
78
+
79
+ # Ensure time_data is not empty before plotting
80
+ if not time_data.empty:
81
+ chart2 = alt.Chart(time_data).mark_line().encode(
82
+ x=alt.X('Year', title='Year'),
83
+ y=alt.Y('License Count', title='Number of Licenses'),
84
+ color=alt.value('blue')
85
+ ).properties(
86
+ width=600,
87
+ height=400,
88
+ title="Number of Licenses Issued Over Time"
89
+ )
90
+ st.altair_chart(chart2)
91
  else:
92
+ st.write("No data available for the 'Licenses Over Time' plot.")
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  # Write-up for Visualization 2
95
  st.write("""