【发布时间】:2021-06-09 14:15:58
【问题描述】:
+-----------------------------------------------------------------------------------------------------------------------------------------------+
|Texts |
+----------------------------------------------------------------------------------------------------------------------------------------------+
|RT @xxxxxx: post aqwe qwqq ssdd qaAQ WQWQW CSDWDW!!!
must RT ! |
|RT @xxxxx: aaa in ssss ssss ss sqqq this qqq in "sss" should xxxx xx at xx xaaaa aqw |
|RT @xxxx: QWW sadad jkhj to hjyhy a eryr rrryryry? ersfsfdsgdgdgg t rtrt ytyyryr.
sadwf wwewe ewewe jyiopo;l dwewre etet of the ddgdg-we dfdfdf, @b… |
+-----------------------------------------------------------------------------------------------------------------------------------------------+
我想使用 scala 和 spark 在列表中的 Text 列中包含这些值行。
1. val newList = myDataframe.select("Texts").rdd.map(_(0)).collect.toList
2. val newList = myDataframe.select("Texts").collect().map(_(0)).toList
newList .foreach(println)
两种方式都没有给出任何输出,程序也没有终止。不会抛出任何错误。
预期输出
["RT @xxxxxx: post aqwe qwqq ssdd qaAQ WQWQW CSDWDW!!! must RT !", "RT @xxxxx: aaa in ssss ssss ss sqqq this qqq in "sss" should xxxx xx at xx xaaaa aqw", "RT @xxxx: QWW sadad jkhj to hjyhy a eryr rrryryry? ersfsfdsgdgdgg t rtrt ytyyryr.
sadwf wwewe ewewe jyiopo;l dwewre etet of the ddgdg-we dfdfdf, @b…"]
请注意数据框中每一行的句子可能包含换行
例如I am going to the the shop.\n Its very expensive
这句话会显示为
I am going to the shop
its very expensive
但两者将属于同一行。
【问题讨论】:
-
缺少其余代码,您显示的行都是正确的 - 只要初始数据帧不是空的,它将返回数据帧中每一行的第一个元素。跨度>
-
@UninformedUser 添加了缺失的代码
-
@UninformedUser 尽管数据框有值,但它不会创建列表。
-
第 1 行和第 2 行都是正确的,代码按预期工作。给我们更多信息,因为问题出在其他地方。
标签: list scala dataframe apache-spark