AzizWazir commited on
Commit
0b2a6a7
·
verified ·
1 Parent(s): ce10ca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -23,7 +23,13 @@ def process_file(uploaded_file):
23
  else:
24
  st.error("Unsupported file format. Please upload Excel, CSV, or PDF.")
25
  return None
 
 
 
 
 
26
  return df
 
27
  except Exception as e:
28
  st.error(f"Error processing file: {e}")
29
  return None
@@ -40,13 +46,21 @@ def main():
40
  if df is not None:
41
  st.subheader("Uploaded Data")
42
  st.write(df.head())
43
-
 
 
 
 
 
 
 
 
44
  # Convert Marks to numeric (if not already numeric)
45
  df['Marks'] = pd.to_numeric(df['Marks'], errors='coerce')
46
-
47
- # Add a Total Marks column (sum of all marks if there are multiple subjects)
48
- # Assuming "Marks" column represents the total of all subjects for simplicity.
49
- df['Total Marks'] = df['Marks'].sum(axis=1)
50
 
51
  # Show the top 10 students based on total marks
52
  top_performers = df.sort_values(by="Total Marks", ascending=False).head(10)
 
23
  else:
24
  st.error("Unsupported file format. Please upload Excel, CSV, or PDF.")
25
  return None
26
+
27
+ # Clean column names (remove spaces or fix names)
28
+ df.columns = df.columns.str.strip()
29
+ st.write("DataFrame columns after cleaning:", df.columns)
30
+
31
  return df
32
+
33
  except Exception as e:
34
  st.error(f"Error processing file: {e}")
35
  return None
 
46
  if df is not None:
47
  st.subheader("Uploaded Data")
48
  st.write(df.head())
49
+
50
+ # Check and debug the column names
51
+ st.write("Columns in the dataset:", df.columns)
52
+
53
+ # Handle missing or incorrectly named columns
54
+ if 'Marks' not in df.columns:
55
+ st.error("The 'Marks' column is missing from the uploaded data!")
56
+ return
57
+
58
  # Convert Marks to numeric (if not already numeric)
59
  df['Marks'] = pd.to_numeric(df['Marks'], errors='coerce')
60
+
61
+ # Add a Total Marks column (assuming a single "Marks" column for simplicity)
62
+ # If you have more subject columns, you could sum across them.
63
+ df['Total Marks'] = df['Marks'] # Modify this if there are more subject columns
64
 
65
  # Show the top 10 students based on total marks
66
  top_performers = df.sort_values(by="Total Marks", ascending=False).head(10)