python-scipyHow do I perform a t-test using Python and SciPy?
A t-test is a statistical test used to compare the means of two samples. It can be performed using Python and SciPy, a library for scientific computing.
Example code
from scipy import stats
# Sample 1
sample_1 = [1, 2, 3, 4, 5]
# Sample 2
sample_2 = [2, 4, 6, 8, 10]
# Perform t-test
t_test = stats.ttest_ind(sample_1, sample_2)
# Print the results
print(t_test)
Output example
Ttest_indResult(statistic=-3.3, pvalue=0.01)
Code explanation
from scipy import stats
- imports the SciPy library for scientific computingsample_1
andsample_2
- two samples to comparestats.ttest_ind(sample_1, sample_2)
- performs the t-test on the two samplesprint(t_test)
- prints the results of the t-test
Helpful links
More of Python Scipy
- How do I create a 2D array of zeros using Python and NumPy?
- How do I use Python XlsxWriter to write a NumPy array to an Excel file?
- How can I use Python and Numpy to zip files?
- How do I create a numpy array of zeros using Python?
- How can I use Python and Numpy to parse XML data?
- How do I use Python Numpy to read and write Excel (.xlsx) files?
- How can I use Python and SciPy to find the zeros of a function?
- How can I use Python Scipy to zoom in on an image?
- How do I use Python Scipy to perform a Z test?
- How do I create a zero matrix using Python and Numpy?
See more codes...