MP12389
MP12389

Reputation: 305

Get rows in numpy array where column contains string

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

Upvotes: 0

Views: 3280

Answers (1)

iacob
iacob

Reputation: 24181

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)]

Upvotes: 2

Related Questions