pandas replace substring code example
Example 1: str replace pandas
>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
0 bao
1 baz
2 NaN
dtype: object
Example 2: replace string if it contains a substring pandas
df_a.loc[df_a.categories.str.contains('beverage'), 'categories'] = 'beverage'
categories product_name
0 beverage coca-cola
1 salty snacks salted pistachios
2 beverage fruit juice
3 beverage lemon tea
4 salty crackers roasted peanuts