In [1]:
import pandas as pd
In [4]:
df = pd.DataFrame({
'name':['john','mary','paul'],
'age':[30,25,40],
'city':['new york','los angeles','london']
})
df
Out[4]:
In [6]:
df.replace([25],40)
Out[6]:
In [8]:
df.replace({
25:26,
'john':'johnny'
})
Out[8]:
In [11]:
df.replace('jo.+','FOO',regex=True)
Out[11]:
In [18]:
df = pd.DataFrame({
'name':['john','mary','paul'],
'num_children':[0,4,5],
'num_pets':[0,1,2]
})
df
Out[18]:
In [19]:
df.replace({'num_pets':{0:1}})
Out[19]:
In [ ]: