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

Question:

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
Asked By: beginner_Coder

||

Answers:

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#'] = ''
Answered By: jezrael
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.