【NLP】文本处理基础操作:停用词,去掉杂乱的词(用nltk),pandas遍历和存储成为txt文件

该博客介绍了如何使用nltk库处理NLP文本,包括去除停用词、转换为小写,以及利用pandas对数据进行遍历、存储为txt文件。还分享了用dropna去除不满足条件数据的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【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'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值