iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use scipy.stats.ttest_ind(a, b) to test whether two independent samples provide evidence of a difference in their population means. SciPy defaults to an equal-variance test; set equal_var=False for Welch’s t-test when you do not want to assume the populations have equal variances. Choose the test’s direction and missing-data handling deliberately, and use a paired test instead when observations are matched or repeated.
Run an independent-samples t-test
Import SciPy’s statistics module, pass the two samples, and inspect the returned result:
from scipy import stats
result = stats.ttest_ind(group_a, group_b, equal_var=False)
print(result.statistic, result.pvalue, result.df)
This example uses Welch’s t-test. The function’s default is equal_var=True, which uses the equal-population-variance form. Set equal_var=False to use Welch’s test, which does not assume equal population variances. Choose the setting based on the analysis, not on which one produces a more favorable p-value.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallThe current SciPy v1.18.0 reference, consulted October 7, 2026, documents this signature:
#1 Best Overall
scipy.stats.ttest_ind(a, b, *, axis=0, equal_var=True, nan_policy='propagate', alternative='two-sided', trim=0, method=None, keepdims=False)
See the official SciPy ttest_ind API reference for the installed version’s exact behavior and compatibility details.
Confirm that the test fits your data
Use it for independent groups
ttest_ind compares the means of two independent samples. Independence is a design requirement: one group’s observations should not be paired with, repeated from, or otherwise dependent on the other group’s observations. If the same people are measured twice or participants are matched, use a paired analysis rather than treating the measurements as independent.
Rank #2
- This guide is a perfect overview for the topics covered in introductory statistics courses.
Choose equal-variance or Welch’s test
With equal_var=True, SciPy uses the form that assumes equal population variances. With equal_var=False, it uses Welch’s test, which allows the population variances to differ. State which form you used when reporting results.
Set the alternative hypothesis before testing
The default alternative='two-sided' tests for a difference in either direction. Use 'greater' when the pre-specified question is whether the first population mean exceeds the second, or 'less' when it is whether the first is lower. These directional alternatives refer to the input order, a then b. Reversing the samples reverses the directional interpretation and the sign of the statistic.
Rank #3
Understand the result
Statistic and direction
The t-statistic is the difference between the sample means, mean(a) - mean(b), divided by its standard error. A positive statistic means the first sample mean is larger; a negative statistic means it is smaller.
P-value and degrees of freedom
The p-value measures how compatible the observed result is with the selected null hypothesis and alternative under the test procedure. It is not the probability that the null hypothesis is true, and it does not measure whether a difference is practically important. The result includes the degrees of freedom for the standard calculation.
Rank #4
Report the difference’s size as well
Include group summaries and an effect estimate or confidence interval when appropriate, rather than reporting only a p-value. The result object documents a confidence-interval method for supported calculations; check your installed SciPy version for its exact behavior.
Free tools Windows power users keep installed
One-click scans. No signup required.
Handle array shapes and missing values
Axis and input shape
Inputs can be array-like. By default, SciPy tests along axis=0, so the arrays must have matching shapes except along the axis being tested. Set axis=None to flatten the inputs before calculation. For batched data, SciPy computes a result for each slice along the selected axis.
Best Value
Choose a NaN policy
The default, nan_policy='propagate', returns NaN for an affected axis slice. With 'omit', NaNs are excluded from that slice; the result is NaN if too little data remains. With 'raise', SciPy raises ValueError when a NaN occurs. Omitting missing values changes which observations contribute, so make that choice consistent with your data-cleaning plan.
Use trimming or resampling only when justified
Trimmed Yuen test
A nonzero trim requests a trimmed (Yuen’s) t-test. SciPy describes trimming a fraction of observations from each tail and using winsorized means in the variance calculation. Its reference recommends considering trimming for long-tailed distributions or data contaminated with outliers. This is a distinct analysis choice, not an automatic switch for deleting outliers.
Permutation or Monte Carlo p-values
By default, SciPy determines the p-value using a theoretical t-distribution. The current API accepts a PermutationMethod or MonteCarloMethod instance through method to configure resampling. Resampling can be computationally expensive, and SciPy cautions that permutation testing is not necessarily more accurate than the analytical test. Older examples using permutations or random_state may not match the current interface; consult the API reference for version-specific details.
Choose the method to match the question
- Independent or paired design: Use
ttest_indfor independent samples, not matched or repeated observations. - Variance assumption: Use
equal_var=Truefor the equal-variance form orFalsefor Welch’s unequal-variance form. - Hypothesis direction: Choose a two-sided or directional alternative before analyzing results, and preserve the stated order of the samples.
- Distribution and outlier approach: Use the ordinary test or a trimmed Yuen test according to the analysis plan.
- P-value calculation: Use the default theoretical distribution or configured resampling method for a reason tied to the analysis.
Do not switch tests merely to obtain a preferred p-value. Match the method to the study design, the quantity you want to estimate, and the assumptions you are prepared to make.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

