To remove unwanted parts from strings in a column with Python Pandas, we can use the map
method.
For instance, we write
data['result'] = data['result'].map(lambda x: x.lstrip('+-').rstrip('aAbBcC'))
to call map
with a lambda function that returns the original string with the unwanted parts removed with lstrip
and rstrip
.
And then we assign the returned results back to the result
column