How to Graph an Electrocardiogram (EKG) in Python (Complete Beginner)

Опубликовано: 13 Июнь 2026
на канале: Proto Bioengineering
25
4

Create a graph of heartbeats from an EKG (as in voltage data from heart muscle contractions) in Python. This tutorial assumes you are new to Python and coding in general.

Kaggle notebook with Python code: https://www.kaggle.com/code/protobioe...

We use the free coding website, Kaggle, to open a file of electrocardiogram (EKG) data and create a graph of real heartbeats. Once you have a free Kaggle account, you can write Python or R code directly on the website without having to download or install anything. Kaggle also has thousands of free datasets to analyze and play around with. Start coding here: https://kaggle.com

DISCLAIMER: DANGER!
This video is for illustrative purposes only. Do not use any information in this video or its associated code or tutorials to make medical decisions for yourself or others. This video was not created by a doctor. If you have any medical concerns, please contact a licensed physician.

*Timeline*
0:00 Danger Disclaimer
0:05 Intro
0:25 About Kaggle, the free coding website
0:45 Open the EKG dataset in a new Kaggle notebook
1:42 Python libraries (or "add-ons")
3:00 Import the libraries for Python that we need
4:47 Open the EKG data with Pandas
5:00 A quick rundown on CSV files
5:44 A quick rundown on variables and functions
7:30 Open the data using Pandas
10:38 Look at the EKG data
11:39 What a heartbeat looks like
12:02 Graph the EKG (channel 1 only)
13:45 About "dataframes"
14:18 Graph EKG channel 2
14:39 Zoom in on the first four heartbeats
16:35 Graph the next four heartbeats
17:45 Add a title
18:45 What are we actually looking at?
19:19 P waves and R waves
20:44 A clean EKG
20:57 The chambers of the heart and the EKG waves they create
22:09 T waves: the electrical reset
23:05 Outro and what is next

*Overall Steps for Graphing an EKG*
1. Get EKG data
2. Import libraries that help open and graph the data (Pandas, Matplotlib)
3. Open the data with the Pandas library
4. Get one of the voltage columns from the data
5. Graph the voltage data with Matplotlib's "plot()" function
6. (Optional) Add a title

*Dataset*
MIT-BIH Normal Sinus Rhythm Database (on Kaggle):
https://www.kaggle.com/datasets/proto...

*Learn More about EKGs*
ECG Basics (NinjaNerd on Youtube):    • ECG Basics | How to Read & Interpret ECGs:...  
ECG Guide (EMCrit): https://emcrit.org/ibcc/ecg/
ECG Basics (practical articles for paramedics and EMS): https://litfl.com/ecg-library/basics/

Please let us know if you have any questions.

Thank you to Anthony Atkielski on Wikimedia for the graphic of a "normal sinus rhythm" heartbeat.