#πŸ”’ pandas str.contains() print out entire row

12 messages Β· Page 1 of 1 (latest)

quiet marlin
#

Using pandas to parse some cvf files. I am trying to use the str.contains() method to single out the rows that include cells that have a string in them but when I run my code I get the result "True" or "False, which looking at the documentation is the expected output. How would I move forward from this and have my code print out or show the full rows with the rest of the columns and the values?

df = pd.read_csv(file)
df = df["Backend"].str.contains('sonic',
                                regex=False)```
lone vectorBOT
#

@quiet marlin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

oak patrol
#

like

df = pd.read_csv(file)
mask = df["Backend"].str.contains('sonic',
                                regex=False)
df[mask]
quiet marlin
#

Thanks, that worked, but what does it do?

oak patrol
#

if they don't have the same length, it'll error

#

iirc, it's called boolean indexing if you want to look it up

quiet marlin
#

Cool. Thanks!

#

!close

lone vectorBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.