Spaces:
Sleeping
Sleeping
| # analyze.py | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # ꡬκΈμνΈ(λλ λ€μ΄λ‘λν CSV) β μ‘°κ±΄λ³ λΉκ΅ λΆμ. | |
| # DBκ° μμΌλ―λ‘ CSV 3κ°λ₯Ό μ§μ μ½λλ€. long-formatμ΄λΌ pivot ν λ²μ΄λ©΄ λ. | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| import pandas as pd | |
| from scipy import stats | |
| # ꡬκΈμνΈμμ λ°μ(νΉμ μ¬μ΄λλ°μμ λ΄λ €λ°μ) CSV 3κ° | |
| participants = pd.read_csv("participants.csv") | |
| messages = pd.read_csv("messages.csv") | |
| surveys = pd.read_csv("surveys.csv") | |
| # 1) μλ£μλ§ | |
| done = participants[participants["completed"] == 1] | |
| print(f"μλ£μ: {len(done)}λͺ ") | |
| print(done["condition"].value_counts()) | |
| # 2) μ¬ν μ€λ¬Έμ wide formatμΌλ‘ (ν λ¬Έν=ν μ΄) | |
| post = surveys[surveys["phase"] == "post"] | |
| post_wide = post.pivot_table(index="participant_id", columns="question_id", | |
| values="answer", aggfunc="first") | |
| # 3) 쑰건과 ν©μΉκΈ° | |
| df = done[["participant_id", "condition"]].merge(post_wide, on="participant_id") | |
| numeric = ["usefulness", "warmth", "competence", "trust", "clarity", "recommend"] | |
| for c in numeric: | |
| df[c] = pd.to_numeric(df[c], errors="coerce") | |
| # 4) μ‘°κ±΄λ³ t-test | |
| print("\n=== μ‘°κ±΄λ³ λΉκ΅ (A: λΆμκ°ν, B: λ©ν ν) ===") | |
| for var in numeric: | |
| a = df[df["condition"] == "A"][var].dropna() | |
| b = df[df["condition"] == "B"][var].dropna() | |
| if len(a) > 1 and len(b) > 1: | |
| t, p = stats.ttest_ind(a, b) | |
| print(f"{var:12s}: A={a.mean():.2f}, B={b.mean():.2f}, t={t:+.2f}, p={p:.3f}") | |