pyspark.sql.functions.bit_count#

pyspark.sql.functions.bit_count(col)[source]#

Returns the number of bits that are set in the argument expr as an unsigned 64-bit integer, or NULL if the argument is NULL.

Added in version 3.5.0.

Parameters:
colColumn or column name

target column to compute on. A column that evaluates to an integral or boolean.

Returns:
Column

the number of bits that are set in the argument expr as an unsigned 64-bit integer, or NULL if the argument is NULL. Returns a column that evaluates to an integer.

Examples

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (0), (1), (2), (3), (NULL) AS TAB(value)"
... ).select("*", sf.bit_count("value")).show()
+-----+----------------+
|value|bit_count(value)|
+-----+----------------+
|    0|               0|
|    1|               1|
|    2|               1|
|    3|               2|
| NULL|            NULL|
+-----+----------------+