df.replace(to_replace ="x",value ="y") -> replacing one value x with y
df.replace(to_replace =["x", "Z"],value ="y") -> replacing more than one value x & z with y
df.replace(to_replace =np.nan,value ="x") -> replacing missing value with x
df.replace("x","y") -> replacing one value x with y
df.replace(["x", "Z"],"y") -> replacing more than one value x & z with y
df.replace(np.nan,"x") -> replacing missing value with x
import numpy as np
import pandas as pd
df = pd.read_csv("bank.csv", sep=';')
# Showing first 50 rows
df[:5]
# replacing "unemployed" with "jobless"
df.replace(to_replace ="unemployed",value ="jobless ")[:5]
# replacing "married", "single" with "private"
df.replace(to_replace =["married", "single"],value ="private")[:5]
#replacing missing values(nan value) in dataframe with value x
# check the second row with index 1, replacing nan (missing value of marital column) with unknown
df.replace(to_replace = np.nan, value ="unknown")[:5]
df.replace("unemployed","jobless ")[:3]
df.replace(np.nan,"unknown")[:3]
df.replace(["married", "single"],"private")[:3]