RDD 有 trim() 函数吗?
is there a trim() function for RDDs?
要删除前导和尾随空格,我知道您可以在数据帧上使用 trim。使用RDD时是否有类似的功能?如果没有,你会怎么做?
编辑:添加了一些代码:
nonNullRDD = marchRDD.filter(lambda row: row.title).filter(lambda row: row.authors)
titleRDD = nonNullRDD.map(lambda field: (field.title, field.authors))
splitRDD = titleRDD.flatMap(lambda field: [(field[0], z) for z in field[1].split(";")])
authorRDD = splitRDD.map(lambda field: [field[1], 1])
test = authorRDD.flatMap(lambda word: word.strip())
RDD 没有字符串函数
我相信你正在寻找 Python str.strip()
trimmed_words = words.map(lambda word: word.strip())
要删除前导和尾随空格,我知道您可以在数据帧上使用 trim。使用RDD时是否有类似的功能?如果没有,你会怎么做?
编辑:添加了一些代码:
nonNullRDD = marchRDD.filter(lambda row: row.title).filter(lambda row: row.authors)
titleRDD = nonNullRDD.map(lambda field: (field.title, field.authors))
splitRDD = titleRDD.flatMap(lambda field: [(field[0], z) for z in field[1].split(";")])
authorRDD = splitRDD.map(lambda field: [field[1], 1])
test = authorRDD.flatMap(lambda word: word.strip())
RDD 没有字符串函数
我相信你正在寻找 Python str.strip()
trimmed_words = words.map(lambda word: word.strip())