df['column name'] = df['column name'].replace(['old value'],'new value')
df["column1"].replace({"a": "x", "b": "y"}, inplace=True)
df.loc[df['column'] == 'column_value', 'column'] = 'new_column_value'
# this will replace "Boston Celtics" with "Omega Warrior"
df.replace(to_replace ="Boston Celtics",
value ="Omega Warrior")
energy['Country'] = energy['Country'].replace(['Afghanistan','Albania'],['Sa','lol'])
# 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 libraries
import 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