Categories
Python Answers

How to filter Python Pandas DataFrame by substring criteria?

Spread the love

To filter Python Pandas DataFrame by substring criteria, we can call the str.contains method.

For instance, we write

df[df['A'].str.contains("hello")]

to return a data frame with rows in column 'A' that has strings containing 'hello' with str.contains.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *