Upload Diploma_result_analysis.py
Browse files- Diploma_result_analysis.py +78 -0
Diploma_result_analysis.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
# Function to find and set the correct header
|
| 5 |
+
def find_and_set_header(df):
|
| 6 |
+
for i in range(5):
|
| 7 |
+
if 'Status' in df.iloc[i].values or 'RESULT' in df.iloc[i].values:
|
| 8 |
+
df.columns = df.iloc[i]
|
| 9 |
+
df = df.drop(index=list(range(i+1)))
|
| 10 |
+
df.reset_index(drop=True, inplace=True)
|
| 11 |
+
return df
|
| 12 |
+
st.error("The uploaded file does not contain 'Status' or 'RESULT' column in the first five rows.")
|
| 13 |
+
return None
|
| 14 |
+
|
| 15 |
+
# Function to analyze the status column
|
| 16 |
+
def analyze_status(df):
|
| 17 |
+
if 'Status' in df.columns:
|
| 18 |
+
status_counts = df['Status'].value_counts()
|
| 19 |
+
elif 'RESULT' in df.columns:
|
| 20 |
+
status_counts = df['RESULT'].value_counts()
|
| 21 |
+
else:
|
| 22 |
+
return None
|
| 23 |
+
return status_counts
|
| 24 |
+
|
| 25 |
+
# Function to handle multiple sheets in Excel file
|
| 26 |
+
def analyze_excel(file):
|
| 27 |
+
xls = pd.ExcelFile(file)
|
| 28 |
+
results = {}
|
| 29 |
+
for sheet_name in xls.sheet_names:
|
| 30 |
+
df = pd.read_excel(file, sheet_name=sheet_name)
|
| 31 |
+
df = find_and_set_header(df)
|
| 32 |
+
if df is not None:
|
| 33 |
+
status_counts = analyze_status(df)
|
| 34 |
+
if status_counts is not None:
|
| 35 |
+
results[sheet_name] = status_counts
|
| 36 |
+
return results
|
| 37 |
+
|
| 38 |
+
# Streamlit app
|
| 39 |
+
def main():
|
| 40 |
+
st.title("Dimploma Students Result Analysis")
|
| 41 |
+
st.write("Upload a CSV or Excel file to analyze student status.")
|
| 42 |
+
|
| 43 |
+
uploaded_file = st.file_uploader("Choose a CSV or Excel file", type=["csv", "xlsx"])
|
| 44 |
+
|
| 45 |
+
if uploaded_file is not None:
|
| 46 |
+
try:
|
| 47 |
+
if uploaded_file.name.endswith('.csv'):
|
| 48 |
+
df = pd.read_csv(uploaded_file)
|
| 49 |
+
df = find_and_set_header(df)
|
| 50 |
+
if df is not None:
|
| 51 |
+
st.write("File uploaded successfully!")
|
| 52 |
+
st.write("Here's a preview of the data:")
|
| 53 |
+
st.dataframe(df.head())
|
| 54 |
+
|
| 55 |
+
status_counts = analyze_status(df)
|
| 56 |
+
if status_counts is not None:
|
| 57 |
+
st.write("### Analysis of Student Status")
|
| 58 |
+
st.write(status_counts)
|
| 59 |
+
st.bar_chart(status_counts)
|
| 60 |
+
|
| 61 |
+
elif uploaded_file.name.endswith('.xlsx'):
|
| 62 |
+
results = analyze_excel(uploaded_file)
|
| 63 |
+
if results:
|
| 64 |
+
for sheet, status_counts in results.items():
|
| 65 |
+
st.write(f"### Analysis of Student Status for sheet: {sheet}")
|
| 66 |
+
st.write(status_counts)
|
| 67 |
+
st.bar_chart(status_counts)
|
| 68 |
+
else:
|
| 69 |
+
st.error("No valid 'Status' or 'RESULT' columns found in any sheets.")
|
| 70 |
+
|
| 71 |
+
else:
|
| 72 |
+
st.error("Unsupported file format.")
|
| 73 |
+
|
| 74 |
+
except Exception as e:
|
| 75 |
+
st.error(f"An error occurred: {e}")
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
main()
|