beginner_Coder
beginner_Coder

Reputation: 51

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

Upvotes: 1

Views: 160

Answers (1)

jezrael
jezrael

Reputation: 863166

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

Upvotes: 1

Related Questions