| student | score | race | gender | income | class_size | |
|---|---|---|---|---|---|---|
| 0 | 0 | 0.801910 | white | female | 2 | 29 |
| 1 | 1 | 0.731556 | white | male | 2 | 18 |
| 2 | 2 | 0.812534 | white | male | 3 | 19 |
| 3 | 3 | 0.829196 | African American | female | 3 | 18 |
| 4 | 4 | 0.706976 | white | female | 3 | 14 |
| student | score | race | gender | income | class_size | |
|---|---|---|---|---|---|---|
| 0 | 0 | 0.801910 | white | female | 2 | 29 |
| 1 | 1 | 0.731556 | white | male | 2 | 18 |
| 2 | 2 | 0.812534 | white | male | 3 | 19 |
| 3 | 3 | 0.829196 | African American | female | 3 | 18 |
| 4 | 4 | 0.706976 | white | female | 3 | 14 |
Text(0.5, 1.0, 'Test scores by income')
stats.t.ppf(1-alpha/2, df)stats.f.ppf(1- alpha, dfb, dfw)import scipy.stats as stats
men = df.loc[df['gender']=='male', 'score']
women = df.loc[df['gender']=='female', 'score']
result = stats.ttest_ind(men, women)
t,p = result
d = result.df
# result.df = attribute, not part of tuple
# cannot be deconstructed.
print(f't: {t}, p: {p}, df: {d}')t: 1.4297999623739412, p: 0.15595477287689072, df: 98.0
import scipy.stats as stats
i1 = df.loc[df["income"] == 1, "score"]
i2 = df.loc[df["income"] == 2, "score"]
i3 = df.loc[df["income"] == 3, "score"]
i4 = df.loc[df["income"] == 4, "score"]
f_return = stats.f_oneway(i1, i2, i3, i4)
print(f_return)F_onewayResult(statistic=np.float64(0.836703537922017), pvalue=np.float64(0.4769781774837194))
import scipy.stats as stats
print("unique values list: ", df["income"].unique())
i1, i2, i3, i4 = [df.loc[df["income"] == i, "score"] for i in df["income"].unique()]
f, p = stats.f_oneway(i1, i2, i3, i4)
print(f"f: {f}, p: {p}")unique values list: [2 3 4 1]
f: 0.8367035379220169, p: 0.4769781774837193