xxxxxxxxxx
df.loc[df['column_name'] == value_you_want_replaced, 'column_name'] = your_value
xxxxxxxxxx
# Replace missing values
df["col"].replace(np.nan, new_val)
# Replace other values
df["col"].str.replace('old','new')
# Replace using masking
df.loc[df['col']=='old', 'col'] = 'new'
# Replace all specified value in the dataframe
df_replaced = df.replace(1, 0)
xxxxxxxxxx
df.replace({'column_name':{'A':0,'B':1},'Sex':{'m':0,'f':1}}, inplace=True)
xxxxxxxxxx
# You can use replace and pass the strings to find/replace as dictionary keys/items:
df.replace({'\n': '<br/>'}, regex=True)
xxxxxxxxxx
# replace() syntax
DataFrame.replace(to_replace="<the_value_you_want_to_replace>", value="<new_value_for_input>", inplace=False, limit=None, regex=False, method='pad')
xxxxxxxxxx
df['column name'] = df['column name'].replace(['old value'], 'new value')