以下代码有效:
likertRoundDfSeq:Seq[DataFrame] = ......
likertRoundDfSeq match
{
case head :: tail => tail.foldLeft(head){(dforg,df1)=>
DataFrameUtils.join(dforg,devianceFromAverageOneRound(df1),"A_RowId")
}
}
但是,我需要添加一个索引作为devianceFromAverageOneRound
我想过用zipWithIndex
做这件事
或许,像这样:
likertRoundDfSeq match
{
case head :: tail => tail.zipWithIndex.foldLeft(head){(dforg,df1)=>
DataFrameUtils.join(dforg,devianceFromAverageOneRound(df1,*myzipindex*),"A_RowId" )
}
}
但我不确定如何在这种情况下突破数据帧和idx。 Intellij似乎没有引导我,所以我有点失落
任何建议都将不胜感激
答案 0 :(得分:2)
你的DF Seq的尾部现在是Tuple2 [DataFrame,Long]的列表,因此你的foldLeft
应该如下所示:
case head :: tail => tail.zipWithIndex.foldLeft(head){ (dforg, df1) =>
DataFrameUtils.join(dforg, devianceFromAverageOneRound(df1._1, df1._2), "A_RowId")
这假设您的新devianceFromAverageOneRound(DataFrame, Long)
仍然返回DataFrame
(而不是Tuple2[DataFrame, Long]
)。