【发布时间】:2021-12-31 13:59:43
【问题描述】:
【问题讨论】:
-
使用:
df['first'].str.replace('jill', 'millie', case=False)
标签: python pandas dataframe replace
【问题讨论】:
df['first'].str.replace('jill', 'millie', case=False)
标签: python pandas dataframe replace
如果你想不分大小写替换,你可以试试:
>> df['first'].str.lower().replace({'jill': 'Millie'}) # if you want to replace multiple values at once
或:
>> import re
>> df['first'].str.replace('jill', 'Millie', flags=re.I) # one replace at a time
【讨论】:
它不起作用,因为您试图替换 jill,但名称实际上是 Jill。试试这个:
df['first'] = df['first'].replace({'Jill': 'Millie'})
【讨论】: