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.

New in version 3.5.0.

Parameters
colColumn or column name

target column to compute on.

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.

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|
+-----+----------------+