I want to check if a pandas dataframe column contains a specific string from a list and if true then put that string into a new column. I know that I possible to do it with many loop but I think that it's going to be very slow according to the number of lines I got in my file.
In [0]: mylist = ['ABC', 'ACB', 'DCB', 'AXR12-1']
In [1]: df
Out[1]:
text
0 ABC KEY778 20225
1 XXX11 K ABC 14452GXX
2 ACB AZZXG112
3 DCB AA112G AXXX
4 DCB AA15G AXR12-1
Result
In [2]: df
Out[2]:
text extract
0 ABC KEY778 20225 ABC
1 XXX11 K ABC 14452GXX ABC
2 ACB AZZXG112 ACB
3 DCB AA112G AXXX DCB
4 DCB AA15G AXR DCB AXR12-1
Do you have a simple way to do that? Thx