Try something like this if you not that familiar with regex:
df.loc[~df['Gender'].isin(['Man', 'Woman']), 'Gender'] = 'Other'
Try this:
df1['Gender'].str.replace(r'(Man)|(Woman)', 'Others')
If something is inside squre brackets '[ ]', then each of the characters are mapped separately. Go to python regex documentation for more details.
[ ] Used to indicate a set of characters. In a set:
Characters can be listed individually, eg [amk] will match 'a', 'm', or 'k'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.