简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM