对PySpark数据框中的列值执行逻辑运算

时间:2017-06-15 05:52:54

标签: python apache-spark dataframe pyspark

我有一个包含多列的数据框,其中一列正在跟随。我想做一些逻辑操作,如如果count> 0.0 将值替换为 1.0 ,否则 0.0 ,并创建另一个标题为标签的列。我怎么能在PySpark中做到这一点

Count
-------
  0
  1
  2
  3
  0
  100

答案

我设法解决了这个问题:

from pyspark.sql.functions import col, when
cond1 = col("Count") > 0.0 
df = df.withColumn("label", when(cond1, 1.0).otherwise(0.0))

0 个答案:

没有答案
相关问题