小编jho*_*jho的帖子

如何在pyspark.sql.funtions.when()中使用多个条件?

我有一个包含几列的数据框.现在我想从其他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.

python apache-spark

22
推荐指数
2
解决办法
5万
查看次数

标签 统计

apache-spark ×1

python ×1