I have the following dataframe as an example:
test = pd.DataFrame({'type':['fruit-of the-loom (sometimes-never)', 'yes', 'ok (not-possible) I will try', 'vegetable', 'poultry', 'poultry'],
'item':['apple', 'orange', 'spinach', 'potato', 'chicken', 'turkey']})
I found many posts of people wanting to remove parentheses from strings or similar situations, but in my case I would like to retain the string exactly as is, except I would like to remove the hyphen
that is inside the parenthesis of the string.
Does anyone have a suggestion on how I could achieve this?
str.split()
would take care of the hyphen if it was leading and str.rsplit()
if it was trailing. I can't think of a way to engage this.
in this case the ideal outcome for the values in this hypothetical column would be:
'fruit-of the-loom (sometimes never)',
'yes',
'ok (not possible) I will try',
'vegetable',
'poultry',
'poultry'`