pyspark.sql.functions.bit_count

pyspark.sql.functions.bit_count(col: ColumnOrName) → pyspark.sql.column.Column[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 str

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

>>> df = spark.createDataFrame([[1],[1],[2]], ["c"])
>>> df.select(bit_count("c")).show()
+------------+
|bit_count(c)|
+------------+
|           1|
|           1|
|           1|
+------------+