| 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)}" | |