答案 0 :(得分:2)
如果您不熟悉正则表达式,请尝试这样的操作:
df.loc[~df['Gender'].isin(['Man', 'Woman']), 'Gender'] = 'Other'
答案 1 :(得分:1)
试试这个:
df1['Gender'].str.replace(r'(Man)|(Woman)', 'Others')
如果方括号 '[ ]' 内有东西,那么每个字符都被单独映射。 前往 python regex documentation 了解更多详情。
<块引用>[ ] 用于表示一组字符。一组:
字符可以单独列出,例如[amk] 将匹配“a”、“m”、 或“k”。