Revision of prior question:
How can I replace all ", " (i.e. comma then space) with "_" except when ", " (comma then space) is followed by the word "LLC" or "Inc" (then do nothing)?
I want to change:
- "TEXAS ENERGY MUTUAL, LLC, BOBBY GILLIAM, STEVE PEREIRA and ANDY STITT"
- "Grape, LLC, Andrea Gray, Jack Smith"
- "Stephen Winters, Apple, pear, Inc, Sarah Smith"
To this:
- "TEXAS ENERGY MUTUAL, LLC_BOBBY GILLIAM_STEVE PEREIRA_ANDY STITT"
- "Grape, LLC_Andrea Gray_Jack Smith"
- "Stephen Winters_Apple_pear, Inc_Sarah Smith"
I thought it would start with some variation of the code below but I cannot figure out the except conditions.
df['Column_Name'] = df['Column_Name'].str.replace(', ','_') Cheers!