Pyspark 函数求反列

fer*_*rmi 5 addition negate pyspark

是否有内置函数来添加新列,该新列是原始列的否定?

Spark SQL有这个功能negative()。Pyspark好像没有继承这个功能。

df_new = df.withColumn(negative("orginal"))
Run Code Online (Sandbox Code Playgroud)

Pie*_*aud 9

假设您的列original是布尔值:

df_new = df.withColumn(~df["original"])  # Equivalent to "not original"
Run Code Online (Sandbox Code Playgroud)