Let's say we have a dataframe- df and a column labelled 'A'. For selecting rows that match ONE string -'some_string', df['A'].str.contains('some_string') works great.
My question is, is there a corresponding method to pass to contains a list of strings, so that partial matches can be gotten? instead of 'some_string' can I give it a list of strings? I am trying to avoid using a for loop and slicing the data frame and concatenating into a new dataframe.
Lets say the dataframe is
pd.DataFrame(np.array([['cat', 2], ['rat', 5], ['ball', 8],['string', 8]]),columns=['A', 'B']))
and
list =['at','ll','ac']
So I want to select the rows with cat, rat, ball. Sorry for the artificially contrived example.
df['A'].str.contains("|".join(list_of_strings)).