0

Pandas Data Frame, I would like to loop over the column named 'first' to verify if is an email or not, if is an email remove it and leave that cell blank.

I have try

for x in df['first']:
     if '.com' in x:
         x = ''
Marioko53
  • 47
  • 5
  • Welcome to Stack Overflow! Please take the [tour] and read [ask]. What's your question? There's more than one problem with this code: 1) that's not how to verify an email address, 2) it doesn't change the cell value. – wjandrea Nov 02 '21 at 23:58
  • Start here: [How to check for valid email address?](/q/8022530/4518341) – wjandrea Nov 02 '21 at 23:59
  • [Please don't post pictures of text](https://meta.stackoverflow.com/q/285551/4518341). Instead, copy the text, [edit] it into your post, and use the formatting tools like [code formatting](/editing-help#code). – wjandrea Nov 03 '21 at 00:07

1 Answers1

1

Answering the pandas portion of this, since that's not exactly email verification.

Use .map with a lambda function for this. This is the preferred way to do what you are trying to do in pandas, instead of iterating.

df['email'] = df['email'].map(lambda x: x if '.com' in x else '')
Ed Kloczko
  • 408
  • 4
  • 6
  • That was pretty close but in this case the code delete the cells I want to keep, I want to delete the emails on that column – Marioko53 Nov 03 '21 at 00:05