Member-only story
How to Find and Replace with Python and Pandas
Documentation for finding and replacing strings and multiple strings at once with Python and Pandas in a Jupyter notebook
6 min readApr 13, 2022
Excel makes finding and replacing values very straightforward and easy. Finding and replacing with Python and Pandas may not be easier than Excel, but it’s certainly more powerful and flexible.
In this tutorial, I’ll show you how to search for specific strings and replace these values.
Let’s begin.
Table of Contents
- Setting up notebook
- Getting some data
- Searching for strings
- Replacing strings
- Replacing multiple strings
Step 1: Set up notebook
First, let’s get a new notebook open and import pandas:
import pandas as pd
Dang, that was easy.
Step 2: Get some data
For this tutorial, we need some text data. After scrounging around kaggle.com for a few minutes, I settled on CNN News Articles from 2011 to 2022.