replace last part of a string in pandas column code example
Example 1: pandas replace word begins with contains
df.sport = df.sport.apply(lambda x: 'ball sport' if 'ball' in x else x)
Example 2: pandas replace word begins with contains
df.sport.str.replace(r'(^.*ball.*$)', 'ball sport')
0 tennis
1 ball sport
2 ball sport
Name: sport, dtype: object