pandas replace regex code example
Example 1: replace column values pandas
df['column'] = df['column'].str.replace(',','-')
df
Example 2: 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 3: str replace pandas
>>> pd.Series(['foo', 'fuz', np.nan]).str.replace('f.', 'ba', regex=True)
0 bao
1 baz
2 NaN
dtype: object