Appending domain name in the csv data rows after finding which rows does not have the domain after user name

Ddevil Prasad Source

I have a data set which contains email address column and some of its values does not contain the "@.gmail.com" string. how can I append this string to those values after finding them in the dataset I have tried to find the rows that have the string in it, as a newbie, following is the code

        import re
        import pandas as pd
        file=pd.read_csv('Data.csv')
        xx = "@gmail.com"
        r1 = re.findall(r"^\w+",xx)
         print(r1)
pythonregexpython-3.xappend

Answers

answered 6 months ago mrzasa #1

You can try to iterate and use good old if and endswith (no regexps). I prepared a simple example (no CSV):

t = ['a', 'b', '[email protected]']
for i, s in enumerate(t):
    if not s.endswith('@gmail.com'):
        t[i] = s + '@gmail.com'

print(t)

comments powered by Disqus