作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在这样的时候评估两个条件:-
import pyspark.sql.functions as F
df = df.withColumn(
'trueVal', F.when(df.value < 1 OR df.value2 == 'false' , 0 ).otherwise(df.value))
df = df.withColumn(
'v',
F.when(df.value < 1,(F.when( df.value =1,0).otherwise(df.value))).otherwise(df.value)
)
'keyword can't be an expression'
用于嵌套 when 语句。
when
中使用多个条件有什么解决办法吗?
最佳答案
pyspark.sql.DataFrame.where
将 bool 列作为其条件。使用 PySpark 时,在阅读“列”时考虑“列表达式”通常很有用。
PySpark 列上的逻辑操作使用 bitwise operators :
&
为 and
|
为 or
~
为 not
<
)结合使用时,通常需要括号。
import pyspark.sql.functions as F
df = df.withColumn('trueVal',
F.when((df.value < 1) | (df.value2 == 'false'), 0).otherwise(df.value))
关于apache-spark - 如何在 Spark 中使用 AND 或 OR 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40686934/
我是一名优秀的程序员,十分优秀!