【问题标题】:Convert RDD of Lists to Dataframe将列表的 RDD 转换为数据框
【发布时间】:2016-05-20 19:38:16
【问题描述】:

我正在尝试将列表中的 RDD 转换为 Spark 中的 Dataframe

RDD:

['ABC', 'AA', 'SSS', 'color-0-value', 'AAAAA_VVVV0-value_1', '1', 'WARNING', 'No test data for negative population! Re-using negative population for non-backtest.']
['ABC', 'SS', 'AA', 'color-0-SS', 'GG0-value_1', '1', 'Temp', 'After, date differences are outside tolerance (10 days) 95.1% of the time']

这是RDD的内容,多个列表。

如何将其转换为数据框?目前,它正在将其转换为单列,但我需要多列。

Dataframe
+--------------+
|            _1|
+--------------+
|['ABC', 'AA...|
|['ABC', 'SS...|

【问题讨论】:

  • 您能否通过打印rdd.take(4) 显示更多关于您的RDD 类型和RDD 头部的信息?您可能需要在转换之前解析数据?
  • RDD中的示例列表['ABC','AA','1','2','This is a ,test model']
  • 我想要这样的东西 column1 column2 column3 column4 AA 1 2 这是一个测试模型
  • 您需要提供reproducible example,以便其他人提供可以真正解决您问题的答案。

标签: scala apache-spark dataframe rdd


【解决方案1】:

只需使用Row.fromSeq:

import org.apache.spark.sql.Row

rdd.map(x => Row.fromSeq(x)).toDF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多