I am extracting email ids and storing them into a new column variable, but I am getting the issue:
import re
def email_extract(comments):
comments1 =re.findall(r'[\w\.-]+@[\w\.-]+',comments)
return comments1
data["email_id"] = data.COMMENTS.apply(lambda x: email_extract(x))
--- TypeError Traceback (most recent call last) <ipython-input-33-d9b73bdc4f8e> in <module>() ----> 1 data["email_id"] = data.COMMENTS.apply(lambda x: email_extract(x)) C:\ProgramData\Anaconda4\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds) 3192 else: 3193 values = self.astype(object).values -> 3194 mapped = lib.map_infer(values, f, convert=convert_dtype) 3195 3196 if len(mapped) and isinstance(mapped[0], Series): pandas/_libs/src\inference.pyx in pandas._libs.lib.map_infer() <ipython-input-33-d9b73bdc4f8e> in <lambda>(x) ----> 1 data["email_id"] = data.COMMENTS.apply(lambda x: email_extract(x)) <ipython-input-32-97f3705d1972> in email_extract(comments) 2 def email_extract(comments): 3 #re_pattern = re.compile(r'[\w\.-]+@[\w\.-]+') ----> 4 comments1 =re.findall(r'[\w\.-]+@[\w\.-]+',comments) 5 return comments1 C:\ProgramData\Anaconda4\lib\re.py in findall(pattern, string, flags) 221 222 Empty matches are included in the result.""" --> 223 return _compile(pattern, flags).findall(string) 224 225 def finditer(pattern, string, flags=0): TypeError: expected string or bytes-like object
How can I fix this issue?