I have a list of elements in string format that I want to search in each row and delete others.
The code below works fine.
However, it replaces the search from the last element of the list.
I am trying to capture every results from the list 'l'.
Please see below for input and expected output.
Code:
l = ['Testing','Goals are met','Mathematics subject','tesTed prototype','Some Test']
df = pd.DataFrame(l)
df.columns = ['l']
Input Data:
l
0 Testing
1 Goals are met
2 Mathematics subject
3 tesTed prototype
4 Some Test
Code to capture the strings contains:
select_list = ["Math",'Test']
for s in select_list:
# keeping into a dataframe
df1 = df[df.l.str.contains(s,case=False)]
df1
Expected output: Notice the code above didn't select the string 'Math' from above.
l
0 Testing
2 Mathematics subject
3 tesTed prototype
4 Some Test