I've got some data in a column (COL_NAME) of a Pandas DataFrame. I'd like to extract some text between '(' and ')' (this data either exists, or the parens don't exist at all, although there may be more than one set of parens in the data). I'd then like to write the data in the paren to another column, and then remove the '(XXX)' from the original string.
I.e.
COL_NAME
========
(info) text (yay!)
I love text
Text is fun
(more info) more text
lotsa text (boo!)
turns in to:
COL_NAME NEW_COL
======== =======
text (yay!) info
i love text None
Text is fun None
more text more info
lots text (boo!) None
I can do this by isolating the column, iterating through its elements, splitting on the (, creating two new lists and then adding them to the DataFrame, but there's assuredly a way more Pythonic/Pandic way of doing this, right?
Thanks!
(info) text yay!), whyinfobut notyay!?lotsa text (boo!)tolots text (boo!)