본문 바로가기

녕's BigData/Python

[Python, 에러] TypeError: expected string or bytes-like object

 

import re
def clean(x):
     x = re.sub("\&\w*\;<.?>", "",str(x))
df['contents'].apply(lambda x: clean(x))

 

정규표현식을 사용해서 문자 제거 도중

타입에러(TypeError) 발생 !

 

변경 전

re.sub("\&\w*\;<.?>", "",x)

 

변경 후

re.sub("\&\w*\;<.?>", "",str(x))

 

x를 str(x)로 변경하였더니 에러가 해결되었다 ^o^