I want to replace all strings that contain a specific substring. So for example if I have this dataframe:
import pandas as pd df = pd.DataFrame({\'name\': [\
You can use apply with a lambda. The x parameter of the lambda function will be each value in the 'sport' column:
x
df.sport = df.sport.apply(lambda x: 'ball sport' if 'ball' in x else x)