I do have a DataFrame like this:
col1 col 2
abc sure
def yes
ghi no
jkl no
mno sure
pqr yes
stu sure
My intention is to rename "sure" and "yes" into "confirm", so that the DataFrame looks like:
col1 col 2
abc confirm
def confirm
ghi no
jkl no
mno confirm
pqr confirm
stu confirm
How to do this :)?
We can use pandas DataFrame rename() function to rename columns and indexes.
You can use the rename() method of pandas. DataFrame to change column/index name individually. Specify the original name and the new name in dict like {original name: new name} to columns / index parameter of rename() . columns is for the column name, and index is for the index name.
You can just:
df = df.replace(['yes','sure'],'confirm')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With