Since you are using pandas, you can invoke apply row-wise and str.contains with regex to find if strings do match. The first step is to find if any of the values match the strings in the substring_list:
df_string.apply(lambda x: x.str.contains('|'.join(substring_list)), axis=1)
this returns:
strings_1 strings_2 strings_3 strings_4
0 True False True False
1 False False False False
2 False False False False
Now, what is not clear though is whether you want to return true if both substrings are present within a row or only either of them. If only either of them, you can simply add any() after the contains() method:
df_string.apply(lambda x: x.str.contains('|'.join(substring_list)).any(), axis=1)
this returns:
0 True
1 False
2 False
dtype: bool
For the second case jpp provides a one line solution with concating row elements into one string, but please note it will not work for corner cases when you have two elems in a row, say, "BBA" and "ABB" and you try to match for "AA". Concated string "BBAABB" will still match "AA", which is wrong. I would like to propose a solution with apply and an extra function, so that code is more readable:
def areAllPresent(vals, patterns):
result = []
for pat in patterns:
result.append(any([pat in val for val in vals]))
return all(result)
df_string.apply(lambda x: areAllPresent(x.values, substring_list), axis=1)
Due to your sample dataframe it will still return the same result, but it works for cases when matching both is necessary:
0 True
1 False
2 False
dtype: bool