Spaces:
Paused
Paused
File size: 753 Bytes
45ef42a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | # 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 |