ProfessorLeVesseur commited on
Commit
2ba307e
1 Parent(s): 2a9a9e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -141,15 +141,14 @@ def main():
141
 
142
  if uploaded_file is not None:
143
  try:
144
- # Step 1: Read the Excel file into a DataFrame and automatically rename duplicate columns
145
- df = pd.read_excel(uploaded_file, mangle_dupe_cols=True)
146
 
147
- # Step 2: Rename duplicate columns to make them more readable if needed
148
- # Columns will already be unique, e.g., "Student Attendance [J]", "Student Attendance [J].1"
149
- df.columns = [col.replace(".1", "_2").replace(".2", "_3") for col in df.columns]
150
 
151
- # Step 3: Replace student names with initials
152
- df = replace_student_names_with_initials(df)
153
 
154
  # Step 4: Display the uploaded data
155
  st.subheader("Uploaded Data")
@@ -272,7 +271,9 @@ def plot_intervention_statistics(intervention_stats):
272
  st.pyplot(fig)
273
 
274
  return fig
 
275
 
 
276
  def compute_student_metrics(df):
277
  # Filter DataFrame for sessions where intervention happened
278
  intervention_df = df[df[INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
@@ -284,8 +285,12 @@ def compute_student_metrics(df):
284
  student_metrics = {}
285
 
286
  for col in student_columns:
287
- # Extract student name or initials, removing any suffixes added for uniqueness
288
- student_name = re.match(r'Student Attendance \[(.+?)\]', col).group(1)
 
 
 
 
289
  # Get the attendance data for the student
290
  student_data = intervention_df[[col]].copy()
291
 
 
141
 
142
  if uploaded_file is not None:
143
  try:
144
+ # Step 1: Read the Excel file into a DataFrame
145
+ df = pd.read_excel(uploaded_file)
146
 
147
+ # Step 2: Manually handle duplicate columns
148
+ df.columns = pd.io.parsers.base.make_unique(df.columns)
 
149
 
150
+ # Step 3: Rename duplicate columns to make them more readable
151
+ df.columns = [f"{col.split('.')[0]}_{i}" if '.' in col else col for i, col in enumerate(df.columns, 1)]
152
 
153
  # Step 4: Display the uploaded data
154
  st.subheader("Uploaded Data")
 
271
  st.pyplot(fig)
272
 
273
  return fig
274
+
275
 
276
+
277
  def compute_student_metrics(df):
278
  # Filter DataFrame for sessions where intervention happened
279
  intervention_df = df[df[INTERVENTION_COLUMN].str.strip().str.lower() == 'yes']
 
285
  student_metrics = {}
286
 
287
  for col in student_columns:
288
+ try:
289
+ # Extract student name or initials, removing any suffixes added for uniqueness
290
+ student_name = re.match(r'Student Attendance \[(.+?)\]', col.split('_')[0]).group(1)
291
+ except AttributeError:
292
+ st.warning(f"Unexpected column name format: {col}. Skipping this column.")
293
+ continue
294
  # Get the attendance data for the student
295
  student_data = intervention_df[[col]].copy()
296