pandas replace data in specific columns with specific values
### replace one value ###
df["column"].replace("US","UK")# you can also use numerical values### replace more than one value ###
df["column"].replace(["man","woman","child"],[1,2,3])# you can also use numerical values# man ==> 1# woman ==> 2# child ==> 3
# change value in column_where_to_change and in the row where column_name == column_value
df.loc[df['<column_name>']=='column_value','<column_where_to_change>']='<new_value>'
# Importing the librariesimport pandas as pd
import numpy as np
# data
Student ={'Name':['John','Jay','sachin','Geetha','Amutha','ganesh'],'gender':['male','male','male','female','female','male'],'math score':[50,100,70,80,75,40],'test preparation':['none','completed','none','completed','completed','none'],}# creating a Dataframe object
df = pd.DataFrame(Student)# Applying the condition
df.loc[df["gender"]=="male","gender"]=1