简体   繁体   中英

How to replace a dataframe column-specific value with a wildcard search using Python

I want to replace dataframe column-specific value which start or ends with specific strings.

Like in below Dataframe I want to replace value with blanks if it contains specific eg. updated string in words

Dataframe

Sr no#
123
abcd
NOTUPDATED
notupdated
Notupdated
Updated
joan aulia UPDATED
nameUPDATED
not

Expected Output

Sr no#
123
abcd
Updated
not

Use Series.str.contains with regex with .+ for any value before updated , $ for end of strings and case=False for ignore cases:

df.loc[df['Sr no#'].str.contains(r'.+updated$', case=False), 'Sr no#'] = ''

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM