Try to search your question here, if you can't find : Ask Any Question Now ?

How to filter a pandas column by list of strings?

HomeCategory: stackoverflowHow to filter a pandas column by list of strings?
pushpa asked 3 weeks ago

The standard code for filtering through pandas would be something like:

output = df['Column'].str.contains('string')
strings = ['string 1', 'string 2', 'string 3']

Instead of ‘string’ though, I want to filter such that it goes through a collection of strings in list, “strings”. So I tried something such as

output = df['Column'].str.contains('*strings')

This is the closest solution I could find, but did not work
How to filter pandas DataFrame with a list of strings

Edit: I should note that I’m aware of the | or operator. However, I’m wondering how to tackle all cases in the instance list strings is changing and I’m looping through varying lists of changing lengths as the end goal.

1 Answers
Best Answer
Fernando answered 3 weeks ago
Your Answer

11 + 13 =

Popular Tags

WP Facebook Auto Publish Powered By :