Spaces:
Paused
Paused
| # src/analysis.py | |
| import pandas as pd | |
| def calculate_correlations(df: pd.DataFrame) -> dict: | |
| correlations = {} | |
| # Overall correlation | |
| overall_corr = df[['Feedback_Stars', 'Instructor_Rating']].corr().iloc[0, 1] | |
| correlations['Overall'] = overall_corr | |
| # Per subject correlation | |
| for subject in df['Subject'].unique(): | |
| subject_df = df[df['Subject'] == subject] | |
| if len(subject_df) > 1: # Need at least 2 data points for correlation | |
| subject_corr = subject_df[['Feedback_Stars', 'Instructor_Rating']].corr().iloc[0, 1] | |
| correlations[subject] = subject_corr | |
| else: | |
| correlations[subject] = None # Not enough data | |
| print("Correlation analysis complete.") | |
| return correlations |