Scala & Spark: Cast multiple columns at once

后端 未结 4 895
小鲜肉
小鲜肉 2020-12-30 15:05

Since the VectorAssembler is crashing, if a passed column has any other type than NumericType or BooleanType and I\'m dealing with a lot of T

4条回答
  •  心在旅途
    2020-12-30 15:35

    I am translating scala program for python. I found smart answer to your problem. The column are named V1 - V28, Time, Amount, Class. (I am not Scala pro) The solution looks like this.

    // cast all the column to Double type.
    val df = raw.select(((1 to 28).map(i => "V" + i) ++ Array("Time", "Amount", "Class")).map(s => col(s).cast("Double")): _*)
    

    The link: https://github.com/intel-analytics/analytics-zoo/blob/master/apps/fraudDetection/Fraud%20Detction.ipynb

提交回复
热议问题