CCockrum commited on
Commit
cb7e6f4
Β·
verified Β·
1 Parent(s): 12bf69a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -6
app.py CHANGED
@@ -212,13 +212,26 @@ if fetch_data:
212
  """
213
  stats_placeholder.markdown(stats_html, unsafe_allow_html=True)
214
 
215
- # πŸ“Š Most Common Subjects
216
- st.subheader("Most Common Subjects")
217
  if 'subject' in metadata_df.columns:
218
- top_subjects = metadata_df['subject'].value_counts().head(10)
219
- st.bar_chart(top_subjects)
220
- else:
221
- st.info("No subject metadata available to display.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
  with st.sidebar.expander("πŸ”— Helpful Resources", expanded=False):
224
  st.markdown("""
 
212
  """
213
  stats_placeholder.markdown(stats_html, unsafe_allow_html=True)
214
 
215
+ # Calculate Top 10 Subjects
 
216
  if 'subject' in metadata_df.columns:
217
+ top_subjects = (
218
+ metadata_df['subject']
219
+ .dropna()
220
+ .str.split(',') # Split multiple subjects per record
221
+ .explode() # Expand into separate rows
222
+ .str.strip() # Remove whitespace
223
+ .value_counts()
224
+ .head(10)
225
+ .to_frame(name="Count")
226
+ )
227
+
228
+ # πŸ“š Most Common Subjects in Sidebar
229
+ with st.sidebar.expander("Top 10 Most Common Subjects", expanded=True):
230
+ st.dataframe(
231
+ top_subjects.style.background_gradient(cmap="Greens").format("{:.0f}"),
232
+ use_container_width=True,
233
+ height=240
234
+ )
235
 
236
  with st.sidebar.expander("πŸ”— Helpful Resources", expanded=False):
237
  st.markdown("""