I have some list values I want to check against another list of conditions.
For example, the condition list I want to check against is ['042', '043', '044']. I want to return True as long as the initial substring contains any of these values.
For example, ['04233'], ['042'] or ['042', '011'] should return True. But for ['11042'] or ['13044'], even though it contains the check conditions as substring, because they are not the initial characters, they should return False.
My code is as follows:
import pandas as pd
df = pd.DataFrame(['152042']) #'04211'
df.columns=['test_list']
cond_list = ['042', '043', '044']
print (df['test_list'].str.contains('|'.join(cond_list)).any())
# Return True, but False is desired.
I am not sure how I can incorporating both substring checking and at the same time ensuring the subtrings occur as leading characters.
^to assert a match at the start of a string