python - Pandas dataframe replace with regex doesn't work -
i have dataframe many rows. want use pd.replace replace values in entire columns.
import pandas pd import re list = ['md 15241', 'md', 'td', 'td 15487'] = pd.dataframe(list) b = a.copy() b.replace(r'[a-z]{2}', 'usa', inplace = true) b
output
0 0 md 15241 1 md 2 td 3 td 15487
i tried r'md' or r'td' , works.
you need regex=true
in replace
method:
b.replace(r'[a-z]{2}', 'usa', inplace=true, regex=true) b #0 #0 usa 15241 #1 usa #2 usa #3 usa 15487
Comments
Post a Comment