首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在PySpark中从单个元素的RDD创建成对RDD?

如何在PySpark中从单个元素的RDD创建成对RDD?
EN

Stack Overflow用户
提问于 2019-04-27 14:00:17
回答 2查看 739关注 0票数 0

这是实际的管道。我正在将文本加载到RDD中。然后我把它清理干净。

代码语言:javascript
运行
复制
rdd1 = sc.textFile("sometext.txt")

import re
import string

def Func(lines):
    lines = lines.lower() #make all text lowercase
    lines = re.sub('[%s]' % re.escape(string.punctuation), '', lines) #remove punctuation
    lines = re.sub('\w*\d\w*', '', lines) #remove numeric-containing strings
    lines = lines.split() #split lines
    return lines
rdd2 = rdd1.flatMap(Func)

stopwords = ['list of stopwords goes here'] 
rdd3 = rdd2.filter(lambda x: x not in stopwords) # filter out stopwords
rdd3.take(5) #resulting RDD

Out:['a',
     'b',
     'c',
     'd',
     'e']

我现在要做的是马尔可夫链函数的开始。我想将每个元素与其连续的元素配对,例如:

('a','b'),('b','c'),('c','d'),('d','e'),等等...

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55877730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档