Home > Software design >  How to replace a dataframe column-specific value with a wildcard search using Python
How to replace a dataframe column-specific value with a wildcard search using Python

Time:09-08

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

CodePudding user response:

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#'] = ''
  • Related