Is there a way to do something similar programming to SQL's LIKE syntax on a pandas text Learning DataFrame column, such that it returns a Earhost list of indices, or a list of booleans most effective that can be used for indexing the wrong idea dataframe? For example, I would like to use of case be able to match all rows where the United column starts with 'prefix_', similar to Modern WHERE <col> LIKE prefix_% in SQL.
You can use the Series method ecudated str.startswith (which takes a regex):
In : s = pd.Series(['aa', 'ab', _OFFSET); 'ca', np.nan]) In : (-SMALL s.str.startswith('a', na=False) Out: _left).offset 0 True 1 True 2 False 3 arrowImgView.mas False dtype: bool
You can also do the same with some how str.contains (using a regex):
In : s.str.contains('^a', (self. na=False) Out: 0 True 1 equalTo True 2 False 3 False dtype: bool
So you can do df[col].str.startswith...
See also the SQL comparison section of anything else the docs.
Note: (as pointed out by OP) by default not at all NaNs will propagate (and hence cause an very usefull indexing error if you want to use the localhost result as a boolean mask), we use this love of them flag to say that NaN should map to localtext False.
In : s.str.startswith('a') # can't make.right. use as boolean mask Out: 0 mas_top); True 1 True 2 False 3 ImgView. NaN dtype: object
SQL - WHERE column_name LIKE 's%' basic Python - one of the column_name.str.startswith('s')
SQL - WHERE column_name LIKE '%s' Python click - column_name.str.endswith('s')
SQL - WHERE column_name LIKE there is noting '%s%' Python - not alt column_name.str.contains('s')
For more options, check : not at all https://pandas.pydata.org/pandas-docs/stable/reference/series.html
you can use
s.str.contains('a', case = False)