Sitemap
Image by 995645 from Pixabay

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

  1. Setting up notebook
  2. Getting some data
  3. Searching for strings
  4. Replacing strings
  5. 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.

--

--

David Allen
David Allen

Written by David Allen

Documentation and tutorials on Python, Pandas, Jupyter Notebook, and Data Analysis.

No responses yet