I have a data-frame that has text in the first column named 'original_column'.
I have successfully been able to pick specific words out of the text column 'original_column' with a list and have them appended to another column and deleted from the original column with the following code:
list1 = {’text’ , ‘and’ , ‘example’}
finder = lambda x: next(iter([y for y in x.split() if y in list1]), None)
df['list1'] = df.original_column.apply(finder)
df['original column']=df['original column'].replace(regex=r'(?i)'+ df['list1'],value="")
I would now like to build on this code by being able to delete ONLY THE FIRST instance of the the specific words in the list from the 'original_column' after appending the listed word to a new column.
The data-frame currently looks like this:
| original column |
__________________________
| text text word |
--------------------------
| and other and |
My current code outputs this:
| original column | list1
______________________________
| word | text
------------------------------
| other | and
My desired to output this:
| original column | list1
_______________________________
| text word | text
-------------------------------
| other and | and