Filter DataFrame Rows With .str.contains()
We’re going to stick with the example that we worked with before, and we’re going to keep looking for secrets. You can do this pretty effectively using pandas. Specifically, you can run it on a
So here we put in
"secret". Now two things about that. What it returns might not be what you’re expecting, so you get a lot of falses here that you see, but this is essentially a mask that pandas creates.
Okay, close, and close also the square bracket. And now if you press Enter, you see that the DataFrame was filtered for only the rows that contain the substring
"secret" inside of the
So I can see that these two, three, four, five, six rows from the DataFrame, the companies have slogans that contain the word
"target secret niches",
brand secret methodologies",
"syndicate secret paradigms", et cetera.
Become a Member to join the conversation.