File size: 1,347 Bytes
38df9d0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import pandas as pd
def analyze_weakness(csv_file):
"""
Analyzes a CSV file with student scores to identify weak topics.
Parameters:
csv_file (file): Uploaded CSV file (must contain 'Topic' and 'Score' columns).
Returns:
str: Analysis report of weak and strong topics.
"""
try:
df = pd.read_csv(csv_file)
if 'Topic' not in df.columns or 'Score' not in df.columns:
return "β CSV must contain 'Topic' and 'Score' columns."
avg_score = df['Score'].mean()
weak_topics = df[df['Score'] < avg_score]
strong_topics = df[df['Score'] >= avg_score]
report = f"π Average Score: {round(avg_score, 2)}\n\n"
report += "β Weak Topics:\n"
if not weak_topics.empty:
report += "\n".join(
[f"- {row['Topic']} ({row['Score']})" for index, row in weak_topics.iterrows()]
)
else:
report += "None π"
report += "\n\nβ
Strong Topics:\n"
if not strong_topics.empty:
report += "\n".join(
[f"- {row['Topic']} ({row['Score']})" for index, row in strong_topics.iterrows()]
)
else:
report += "None"
return report
except Exception as e:
return f"Error analyzing file: {str(e)}"
|