Scala: How can I replace value in Dataframes using scala

Spark 1.6.2, Java code (sorry), this will change every instance of Tesla to S for the entire dataframe without passing through an RDD:

dataframe.withColumn("make", when(col("make").equalTo("Tesla"), "S")
                             .otherwise(col("make") 
                    );

Edited to add @marshall245 “otherwise” to ensure non-Tesla columns aren’t converted to NULL.

Leave a Comment