이런 데이터셋에서 '감동/감탄' 등 텍스트만 뽑기 위한 전처리
전체 데이터프레임의 컬럼들을 for문으로 돌면서 apply
for col in emotion_df.columns:
emotion_df[col] = emotion_df[col].apply(lambda x: x[1:-1].split(',')[0])
정규표현식 적용하기
- '/'문자를 살리기위해 "\/" 추가
- progress_apply와 tqdm을 사용하면 진행도 표시 가능
import re
def preprocessing(text):
# 한글, 영문, 숫자만 남기고 모두 제거하도록 합니다.
text = re.sub('[^가-힣ㄱ-ㅎㅏ-ㅣa-zA-Z0-9\/]', '', text)
return text
# tqdm 으로 전처리 진행 상태를 표시
from tqdm import tqdm
tqdm.pandas()
# map을 통해 전처리 일괄 적용
for col in emotion_df.columns:
emotion_df[col] = emotion_df[col].progress_apply(preprocessing)
map
- 하나의 칼럼에만 적용할땐 map 사용
- progress_map() 가능
def full_text(content):
return ''.join(content)
df['content_full']= df["blog_content"].map(full_text)
df['content_full']