所以我寫的基礎上(即不工作)如何在我的數據幀平均每FloatType柱像這樣:將集合功能對某些類型的每一列
val descript = df.dtypes
var decimalArr = new ListBuffer[String]()
for(i <- 0 to (descript.length - 1)) {
if(descript(i)._2 == "FloatType") {
decimalArr += descript(i)._1
}
}
//Build Statsitical Arguments for DataFrame Pass
var averageList = new ListBuffer[String]()
for(i <- 0 to (decimalArr.length - 1)){
averageList += "avg(" + '"' + decimalArr(i) + '"' + ")"
}
//sample statsitical call
val sampAvg = df.agg(averageList).show
即得到由averageList生產的例子是:
ListBuffer(avg("offer_id"), avg("decision_id"), avg("offer_type_cd"), avg("promo_id"), avg("pymt_method_type_cd"), avg("cs_result_id"), avg("cs_result_usage_type_cd"), avg("rate_index_type_cd"), avg("sub_product_id"))
將澄清的問題是,VAL sampAvg = df.agg(averageList).show不允許listBuffer作爲輸入。所以即使把它.toString不工作,它想要org.apache.spark.sql.Column *。有沒有人知道我可以用我嘗試的方式做點什麼。
旁註我在星火1.3
您是否嘗試過在平均列表中使用sc.parallelize,然後使用.toDF()函數? – Niemand