0

I currently have a code in which I'm using withColumn() to create the columns and use when statement to decide the values for that column, However I'm looking for an approach to implement it in a function call that creates the column name dynamically and also applies the when condition to assign the value to its respective columns. Below is the Code

DF = DF.withColumn("InL",abs(when(((col("A") == "String")|(col("A") == 
            "String"))&(col("B")=='String"),col("B"))))\
       .withColumn("InK",abs(when(((col("A") == "String")|(col("A") == 
            "String"))&(col("B")=='String"),abs(col("B"))/100))

The number of withColumns is increasing with new column names and hence looking for an approach that could simplify the solution

Thanks in Advance

0 Answers0