pandas regex replace code example
Example 1: pandas replace values in column regex
# replace the matching strings
df_updated = df.replace(to_replace ='[nN]ew', value = 'New_', regex = True)
# Print the updated dataframe
print(df_updated)
Example 2: str replace pandas
>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
0 bao
1 baz
2 NaN
dtype: object