Is there a built-in function to add a new column which is the negation of the original column?
Spark SQL has the function negative()
. Pyspark does not seem to have inherited this function.
df_new = df.withColumn(negative("orginal"))
Is there a built-in function to add a new column which is the negation of the original column?
Spark SQL has the function negative()
. Pyspark does not seem to have inherited this function.
df_new = df.withColumn(negative("orginal"))
Assuming your column original
is boolean :
df_new = df.withColumn(~df["original"]) # Equivalent to "not original"
~
then it is going to be executed in a python process using memory overhead, not in the JVM. Is there an alternative that will be executed within the JVM only? –
Nicotiana I think it should be this to be syntax right, based on @pierre-gourseaud's answer:
df_new = df.withColumn("new_column_name", ~df["original"]) # Equivalent to "not original"
© 2022 - 2024 — McMap. All rights reserved.