Python Z-Score Explained: Code Example with Numpy, SciPy & Pandas

Опубликовано: 19 Апрель 2026
на канале: Ryan & Matt Data Science
1,968
53

🧠 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...

Want to detect outliers or standardize your data in Python? This tutorial breaks down the Z-Score in plain English—with real code examples using NumPy, SciPy, and Pandas. Perfect for data science beginners, analysts, and anyone working with statistical data!

Code: https://ryanandmattdatascience.com/py...

🚀 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  
Python Quantiles:    • Understanding Quantiles in Python: A Step-...  
Python STD Variance:    • How to Calculate Standard Deviation & Vari...  
Python Coef of Variation:    • What is Coefficient of Variation? Python E...  


In this video, I walk you through everything you need to know about Z-scores and outlier detection in Python. We cover three complete examples that show you exactly how to calculate Z-scores and identify outliers in your datasets. The first example uses NumPy for a manual calculation approach, the second leverages SciPy for a streamlined one-line solution, and the third example demonstrates how to work with Pandas DataFrames to detect, label, and remove outliers from real data.

I also explain the 68-95-99.7 rule for normal distributions so you understand what Z-scores actually mean and when a data point should be considered an outlier. By the end of this tutorial, you'll know how to calculate Z-scores manually, use built-in library functions, create outlier columns in your DataFrames, and filter out extreme values that could skew your analysis or machine learning models.

Whether you're cleaning data for a project or preparing datasets for predictive modeling, understanding Z-scores and outlier removal is an essential skill. This step-by-step guide makes it easy to apply these concepts in your own Python code, with clear examples you can follow along with and replicate.

TIMESTAMPS
00:00 Introduction to Z-Scores and Outlier Removal
00:42 Understanding Z-Scores and the 68-95-99.7 Rule
01:07 Calculating Z-Scores: Step-by-Step Example
02:04 The Normal Distribution and Standard Deviations
02:53 Setting Up Python Libraries
03:15 Example 1: Manual Z-Score Calculation with NumPy
05:17 Example 2: Using SciPy for Z-Scores
06:02 Example 3: Pandas DataFrames and Outlier Detection
07:32 Creating Normal Distribution Data
08:15 Adding Z-Score Column to DataFrame
10:00 Validating the 68-95-99.7 Rule
12:02 Creating and Labeling Outlier Column
13:12 Identifying Top and Bottom Outliers
13:52 Removing Outliers from DataFrame
15:23 Video Recap and Key Takeaways

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.