我在https://databricks.com/blog/2015/02/17/introducing-dataframes-in-spark-for-large-scale-data-science.html上看到了一个Dataframes教程,这个教程写在Python
。我正试图将它翻译成Scala
。火花在地图中创建行
他们有下面的代码:
df = context.load("/path/to/people.json")
# RDD-style methods such as map, flatMap are available on DataFrames
# Split the bio text into multiple words.
words = df.select("bio").flatMap(lambda row: row.bio.split(" "))
# Create a new DataFrame to count the number of words
words_df = words.map(lambda w: Row(word=w, cnt=1)).toDF()
word_counts = words_df.groupBy("word").sum()
于是,我第一次看到从csv
数据到一个数据帧df
后来才知道有:
val title_words = df.select("title").flatMap { row =>
row.getAs[String("title").split(" ") }
val title_words_df = title_words.map(w => Row(w,1)).toDF()
val word_counts = title_words_df.groupBy("word").sum()
,但我不知道:
如何将字段名称分配到行中的行开头与VAL title_words_df nning = ...
我有错误 “的值toDF不是org.apache.spark.rdd.RDD [org.apache.spark.sql.Row]成员”
在此先感谢您的帮助。