我有一个包含几列的数据框.现在我想从其他2列中派生出一个新列:
from pyspark.sql import functions as F
new_df = df.withColumn("new_col", F.when(df["col-1"] > 0.0 & df["col-2"] > 0.0, 1).otherwise(0))
Run Code Online (Sandbox Code Playgroud)
有了这个,我只得到一个例外:
py4j.Py4JException: Method and([class java.lang.Double]) does not exist
Run Code Online (Sandbox Code Playgroud)
它适用于这样的一个条件:
new_df = df.withColumn("new_col", F.when(df["col-1"] > 0.0, 1).otherwise(0))
Run Code Online (Sandbox Code Playgroud)
有谁知道使用多个条件?
我正在使用Spark 1.4.