Re: Addign a new column to a dataframe (based on value of existing column)

2016-04-28 Thread Marco Mistroni
many thx Nick kr On Thu, Apr 28, 2016 at 8:07 PM, Nick Pentreath wrote: > This should work: > > scala> val df = Seq((25.0, "foo"), (30.0, "bar")).toDF("age", "name") > scala> df.withColumn("AgeInt", when(col("age") > 29.0, > 1).otherwise(0)).show > +++--+

Re: Addign a new column to a dataframe (based on value of existing column)

2016-04-28 Thread Nick Pentreath
This should work: scala> val df = Seq((25.0, "foo"), (30.0, "bar")).toDF("age", "name") scala> df.withColumn("AgeInt", when(col("age") > 29.0, 1).otherwise(0)).show +++--+ | age|name|AgeInt| +++--+ |25.0| foo| 0| |30.0| bar| 1| +++--+ On Thu, 28 Apr 2016 at

Addign a new column to a dataframe (based on value of existing column)

2016-04-28 Thread Marco Mistroni
HI all i have a dataFrame with a column ("Age", type double) and i am trying to create a new column based on the value of the Age column, using Scala API this code keeps on complaining scala> df.withColumn("AgeInt", if (df("Age") > 29.0) lit(1) else lit(0)) :28: error: type mismatch; found :