Dataframe: Clean cells containing specific value

Viewed 48

I have this dataframe:

Name Phone / Mail
Max 0176348334
Celine celine@mail.com
... ...

How do I edit all the cells containin "@"?

So the result should be like this:

Name Phone / Mail
Max 0176348334
Celine Please fill in Phone Number
... ...

Thank you!

1 Answers

Use loc:

df.loc[df['Phone / Mail'].str.contains('@'), 'Phone / Mail'] = 'Please fill in Phone Number'

Or np.where:

df['Phone / Mail'] = np.where(df['Phone / Mail'].str.contains('@'), df['Phone / Mail'], 'Please fill in Phone Number')

Just filter the occurrences of the @ sign.

Related