Skip to main content

bit_xor

Returns the bitwise XOR of all non-null input values, or null if none.

Syntax

Python
from pyspark.sql import functions as sf

sf.bit_xor(col)

Parameters

Parameter

Type

Description

col

pyspark.sql.Column or column name

Target column to compute on.

Returns

pyspark.sql.Column: the bitwise XOR of all non-null input values, or null if none.

Examples

Example 1: Bitwise XOR with all non-null values

Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([[1],[1],[2]], ["c"])
df.select(sf.bit_xor("c")).show()
Output
+----------+
|bit_xor(c)|
+----------+
| 2|
+----------+

Example 2: Bitwise XOR with some null values

Python
from pyspark.sql import functions as sf
df = spark.createDataFrame([[1],[None],[2]], ["c"])
df.select(sf.bit_xor("c")).show()
Output
+----------+
|bit_xor(c)|
+----------+
| 3|
+----------+