【NLP】文本处理基础操作:停用词,去掉杂乱的词(用nltk),pandas遍历和存储成为文件
程序代码以及说明
利用这段程序完成了把一个csv第一行是情感,第二行是评论的数据去掉乱七八糟的字符和完成小写之后,存到了一个txt文件里面
当然整体的程序可能不是很重要
重要的是里面处理的步骤和特定的语法
下面拆开来讲
import pandas as pd
import numpy as np
from nltk.tokenize import RegexpTokenizer
FILE_PATH = 'E:\data1_movie.csv'
df = pd.read_csv(FILE_PATH)
tokenizer = RegexpTokenizer(r'\w+')
stopwords = [['i', 'me', 'my', 'myself', 'we', 'our', 'ours', 'ourselves', 'you', 'your', 'yours', 'yourself', 'yourselves', 'he', 'him', 'his', 'himself', 'she', 'her', 'hers', 'herself', 'it', 'its', 'itself', 'they', 'them', 'their', 'theirs', 'themselves', 'what', 'which', 'who', 'whom', 'this', 'that', 'these', 'those', 'am', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had', 'having', 'do', 'does', 'did', 'doing', 'a', 'an', 'the', 'and', 'but', 'if', 'or', 'because', 'as', 'until', 'while', 'of', 'at', 'by', 'for', 'with', 'about', 'against', 'between', 'into', 'through', 'during', 'before', 'after', 'above'