PySpark: multiple conditions in when clause - Stack Overflow
stackoverflow.com › questions › 37707305Jun 8, 2016 · PySpark: multiple conditions in when clause. I would like to modify the cell values of a dataframe column (Age) where currently it is blank and I would only do it if another column (Survived) has the value 0 for the corresponding row where it is blank for Age. If it is 1 in the Survived column but blank in Age column then I will keep it as null. I tried to use && operator but it didn't work.
PySpark DataFrame withColumn multiple when conditions
stackoverflow.com › questions › 61926454Jul 2, 2021 · PySpark DataFrame withColumn multiple when conditions. How can i achieve below with multiple when conditions. from pyspark.sql import functions as F df = spark.createDataFrame ( [ (5000, 'US'), (2500, 'IN'), (4500, 'AU'), (4500, 'NZ')], ["Sales", "Region"]) df.withColumn ('Commision', F.when (F.col ('Region')=='US',F.col ('Sales')*0.05).\. F.when (F.col ('Region')=='IN',F.col ('Sales')*0.04).\.
pyspark.sql.functions.when — PySpark 3.3.1 documentation
spark.apache.org › pysparkpyspark.sql.functions.when(condition: pyspark.sql.column.Column, value: Any) → pyspark.sql.column.Column [source] ¶. Evaluates a list of conditions and returns one of multiple possible result expressions. If pyspark.sql.Column.otherwise () is not invoked, None is returned for unmatched conditions. New in version 1.4.0. a boolean Column expression.