pythonintermediate

Statistical Analysis with SciPy

Run hypothesis tests, correlations, and descriptive statistics on dataset columns with SciPy.

python
from scipy import stats
import numpy as np

np.random.seed(42)
group_a = np.random.normal(50, 10, 100)
group_b = np.random.normal(55, 10, 100)

t_stat, p_value = stats.ttest_ind(group_a, group_b, equal_var=False)
print(f't={t_stat:.3f}, p={p_value:.4f}')

u_stat, p_mw = stats.mannwhitneyu(group_a, group_b, alternative='two-sided')
print(f'U={u_stat:.0f}, p={p_mw:.4f}')

corr, p_corr = stats.pearsonr(group_a, group_b)
print(f'r={corr:.3f}, p={p_corr:.4f}')

Use Cases

  • A/B testing
  • data exploration
  • reporting pipelines

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.