我是数据工程/机器学习和自学的新学生。在处理示例问题时,我遇到了以下数据清理任务
1. Remove extra whitespaces (keep one whitespace in between word but remove more
than one whitespaces) and punctuations
2. Turn all the words to lower case and remove stop words (list from NLTK)
3. Remove duplicate words in ASSEMBLY_NAME column
Run Code Online (Sandbox Code Playgroud)
尽管我在大学作业期间一直在编写代码来执行这些任务,但我从未在任何项目中使用过一段代码来完成这些任务,并且我正在寻求专家的指导,他们可以通过指出来帮助我寻求完成任务的最佳方法(in python or scala)
目前已完成的工作:
1.从parquet文件中读取数据
partFitmentDF = sqlContext.read.parquet("/mnt/blob/devdatasciencesto/pga-parts-forecast/raw/parts-fits/")
display(partFitmentDF)
Run Code Online (Sandbox Code Playgroud)
partFitmentDF.createOrReplaceTempView("partsFits")
partFitmentDF.write.mode("overwrite").format("delta").saveAsTable("partsFitsTable")
Run Code Online (Sandbox Code Playgroud)
3. 重新排列表中的 Fits_Assembly_name 数据,以便每个不同的 Itemno 的所有 Fits_Assembly_Name 和 Fits_Assembly_ID 都滚动到单行
%sql
select itemno, concat_ws(' | ' , collect_set(cast(fits_assembly_id as int))) as fits_assembly_id, concat_ws(' | ' …Run Code Online (Sandbox Code Playgroud) 当我编译代码时,出现以下错误:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from nameparser.parser import HumanName
ImportError: No module named nameparser.parser
Run Code Online (Sandbox Code Playgroud)
我该如何纠正?
我写了下面的代码,我想打印出前 10 个句子中的单词,并且我想删除所有不是名词、动词、形容词、副词或专有名称的单词。但我不知道怎么做?谁能帮我?
! pip install wget
import wget
url = 'https://raw.githubusercontent.com/dirkhovy/NLPclass/master/data/moby_dick.txt'
wget.download(url, 'moby_dick.txt')
documents = [line.strip() for line in open('moby_dick.txt', encoding='utf8').readlines()]
import spacy
nlp = spacy.load('en')
tokens = [[token.text for token in nlp(sentence)] for sentence in documents[:200]]
pos = [[token.pos_ for token in nlp(sentence)] for sentence in documents[:100]]
pos
Run Code Online (Sandbox Code Playgroud) 我想知道是否有一个库或函数可以返回一个数字,如果输入是两个字符串,输出应该是两个字符串中重新出现的单词的数量一个例子...
输入:
string 1= my name is user
string 2= my friend is here
Run Code Online (Sandbox Code Playgroud)
输出:
2
Run Code Online (Sandbox Code Playgroud)
因为"我的"和"是"在两个字符串中重复...我听说nltk可以帮助我,如果真的可以有人请指导我的功能...请帮助我
我正在尝试标记我的pandas系列中的每个句子。我尝试按照文档中的说明使用 apply 进行操作,但没有成功:
x.apply(nltk.word_tokenize)
Run Code Online (Sandbox Code Playgroud)
如果我只是使用nltk.word_tokenize(x)也不起作用,因为x不是字符串。有人有什么想法吗?
编辑:x是一系列pandas句子:
0 A very, very, very slow-moving, aimless movie ...
1 Not sure who was more lost - the flat characte...
2 Attempting artiness with black & white and cle...
Run Code Online (Sandbox Code Playgroud)
与x.apply(nltk.word_tokenize)它返回完全相同:
0 A very, very, very slow-moving, aimless movie ...
1 Not sure who was more lost - the flat characte...
2 Attempting artiness with black & white and cle...
Run Code Online (Sandbox Code Playgroud)
错误nltk.word_tokenize(x)是: …
我想过滤掉推文中的成人内容(或任何文本).
对于垃圾邮件检测,我们有数据集可以检查特定文本是垃圾邮件还是火腿.
对于成人内容,我找到了我想要使用的数据集(下面提取):
arrBad = [
'acrotomophilia',
'anal',
'anilingus',
'anus',
.
. etc.
.
'zoophilia']
Run Code Online (Sandbox Code Playgroud)
题
如何使用该数据集过滤文本实例?
我想找到两个同义词之间的相关性,我遇到了许多算法,如resnik,lin,wu palmer,路径算法,leacock chodorow等.有人能告诉我哪些算法最有效吗?
lexpr究竟是什么意思,以及r'/ F xx的含义是什么?什么是Application Expression?
from nltk.sem.logic import *
lexpr = Expression.fromstring
zero = lexpr(r'\F x.x')
one = lexpr(r'\F x.F(x)')
two = lexpr(r'\F x.F(F(x))')
three = lexpr(r'\F x.F(F(F(x)))')
four = lexpr(r'\F x.F(F(F(F(x))))')
succ = lexpr(r'\N F x.F(N(F,x))')
plus = lexpr(r'\M N F x.M(F,N(F,x))')
mult = lexpr(r'\M N F.M(N(F))')
pred = lexpr(r'\N F x.(N(\G H.H(G(F)))(\u.x)(\u.u))')
v1 = ApplicationExpression(succ, zero).simplify()
Run Code Online (Sandbox Code Playgroud) 嗨我第一次使用nltk,我想使用nltk从文本中提取动作/任务
Hi prakash, how are you ?. We need to complete the speech to action by 8 June then you will have to finish the UI by 15 july
Run Code Online (Sandbox Code Playgroud)
在这里,演讲与行动和UI 是行动.
我已经开始创建令牌,不知道下一步该做什么,请指导.
from nltk import sent_tokenize
sample_text ="""Hi prakash, how are you ?. We need to complete the speech to action demo by 8 June then you will have to finish the Ui by 15 july"""
sentences = sent_tokenize(sample_text)
print(sentences) import nltk
from nltk.tag import pos_tag
from …Run Code Online (Sandbox Code Playgroud)