how to convert row from csv to ArrayType in Apache spark java?

huangapple go评论75阅读模式
英文:

how to convert row from csv to ArrayType in Apache spark java?

问题

我有一个包含1万行的CSV文件,想要找出一些模式。我参考了Apache Spark文档中的示例。在下面的示例中,我将列出的项目替换为列的列表,但是出现了错误。

输入列必须为ArrayType,但实际为StringType

FPGrowthModel model = new FPGrowth()
  .setItemsCol("items")
  .setMinSupport(0.5)
  .setMinConfidence(0.6)
  .fit(itemsDF);

如何创建ArrayType

英文:

I have a CSV of 10k rows and I want to find out some pattern. I am referring example for Apache Spark docs. In below example in place of items I am giving list of columns, but getting error.

The input column must be ArrayType, but StringType.

FPGrowthModel model = new FPGrowth()
  .setItemsCol("items")
  .setMinSupport(0.5)
  .setMinConfidence(0.6)
  .fit(itemsDF);

How to create ArrayType?

答案1

得分: 0

尝试这个 -

val new_itemsDF = itemsDF.withColumn("items", array(col("items")))
FPGrowthModel model = new FPGrowth()
  .setItemsCol("items")
  .setMinSupport(0.5)
  .setMinConfidence(0.6)
  .fit(new_itemsDF);
英文:

Try this-

val new_itemsDF = itemsDF.withColumn("items", array(col("items")))
FPGrowthModel model = new FPGrowth()
  .setItemsCol("items")
  .setMinSupport(0.5)
  .setMinConfidence(0.6)
  .fit(new_itemsDF);

huangapple
  • 本文由 发表于 2020年8月5日 17:26:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/63262194.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定