Add Column To Pyspark Dataframe Based On A Condition
My data.csv file has three columns like given below. I have converted this file to python spark dataframe. A B C | 1 | -3 | 4 | | 2 | 0 | 5 | | 6 | 6 | 6 | I want to add
Solution 1:
Try something like this:
from pyspark.sql import functions as f
df.withColumn('D', f.when(f.col('B') > 0, "Yes").otherwise("No")).show()
Post a Comment for "Add Column To Pyspark Dataframe Based On A Condition"