How to Perform a Paired T-Test in Python (Scipy & Numpy)

Опубликовано: 18 Март 2026
на канале: Ryan & Matt Data Science
685
26

🧠 Don’t miss out! Get FREE access to my Skool community — packed with resources, tools, and support to help you with Data, Machine Learning, and AI Automations! 📈 https://www.skool.com/data-and-ai-aut...

Need to compare two related samples—like before-and-after test scores or matched observations? In this step-by-step tutorial, you’ll learn how to run a paired t-test using Python, with real examples using NumPy and SciPy.


🚀 Hire me for Data Work: https://ryanandmattdatascience.com/da...
👨‍💻 Mentorships: https://ryanandmattdatascience.com/me...
📧 Email: [email protected]
🌐 Website & Blog: https://ryanandmattdatascience.com/
🖥️ Discord:   / discord  
📚 *Practice SQL & Python Interview Questions: https://stratascratch.com/?via=ryan
📖 *SQL and Python Courses: https://datacamp.pxf.io/XYD7Qg

🍿 WATCH NEXT
Statistics for Data Science Playlist:    • Statistics for Data Science  
Shapiro Wilk Test:    • How to Perform the Shapiro-Wilk Test for N...  
Two Sample T Test:    • Independent Two-Sample T-Test (Same Varian...  
Chi Square Independence:    • Performing a Chi-Square Test for Independe...  


In this video, I break down the paired t-test in Python and show you exactly when and how to use it. The paired t-test is one of the most useful statistical tests for comparing before-and-after measurements, and I walk you through everything from manual calculations to fast shortcuts using SciPy.

We start with the fundamentals: what a paired t-test is, when you should use it, and the key assumptions like normality and independence. Then I dive into Python code with three detailed examples—marathon training times, Metallica ticket sales before and after the Black Album, and the impact of baseball changes on home runs.

You'll see how to calculate differences, check for normal distribution using the Shapiro-Wilk test, compute t-statistics, and interpret p-values for both two-tailed and one-tailed tests. I also show you the manual process step-by-step so you understand what's happening under the hood, then reveal how SciPy makes everything way easier with just a few lines of code.

By the end of this video, you'll know how to confidently run paired t-tests in Python, interpret results correctly, and avoid common mistakes. Whether you're analyzing training data, medical outcomes, or sales performance, this tutorial gives you the tools you need to make data-driven decisions with statistical confidence.

TIMESTAMPS
00:00 Introduction to Paired T-Test
01:13 Steps for Paired T-Test
01:49 Example Overview: Metallica Ticket Sales
03:55 Getting Started with Python Code
04:43 Example 1: Marathon Times (Manual Calculation)
06:02 Calculating Differences and Statistics
07:32 Shapiro-Wilk Normality Test
08:15 T-Statistic and P-Value Calculation
09:22 Example 2: Metallica Ticket Sales (Simplified Method)
11:40 Using stats.ttest_rel Shortcut
12:40 Example 3: Right-Tailed Test (Baseball Hitting Coach)
15:17 One-Tailed P-Value Adjustment
16:02 Example 4: Left-Tailed Test (Baseball Change Impact)
19:03 Final Results and Conclusion

OTHER SOCIALS:
Ryan’s LinkedIn:   / ryan-p-nolan  
Matt’s LinkedIn:   / matt-payne-ceo  
Twitter/X: https://x.com/RyanMattDS

Who is Ryan
Ryan is a Data Scientist at a fintech company, where he focuses on fraud prevention in underwriting and risk. Before that, he worked as a Data Analyst at a tax software company. He holds a degree in Electrical Engineering from UCF.

Who is Matt
Matt is the founder of Width.ai, an AI and Machine Learning agency. Before starting his own company, he was a Machine Learning Engineer at Capital One.

*This is an affiliate program. We receive a small portion of the final sale at no extra cost to you.