0

I have a numpy array with 4 columns. The first column is text.

I want to retrieve every row in the array where the first column contains a substring.

Example: if the string I'm searching for is "table", find and return all rows in the numpy array whose first column contains "table."

I've tried the following:

rows = nparray[searchString in nparray[:,0]]

but that doesn't seem to work

MP12389
  • 175
  • 1
  • 1
  • 9

1 Answers1

1

Given a pandas DataFrame df, this will return all rows where searchString is a substring of the value in the column column:

searchString = "table"

df.loc[df['column'].str.contains(searchString, regex=False)]
iacob
  • 14,010
  • 5
  • 54
  • 92
  • 1
    Yep, after Paula Thomas led me down the pandas track, I came across this https://stackoverflow.com/questions/27975069/how-to-filter-rows-containing-a-string-pattern-from-a-pandas-dataframe/27975191, which is the same thing. Thanks! – MP12389 Jul 06 '18 at 17:24
  • 1
    Add `regex=False` for a trivial speed-up. – jpp Jul 06 '18 at 17:24