pyspark.sql.functions.cardinality#
- pyspark.sql.functions.cardinality(col)[source]#
Collection function: returns the length of the array or map stored in the column.
New in version 3.5.0.
Examples
>>> import pyspark.sql.functions as sf >>> spark.createDataFrame( ... [([1, 2, 3],),([1],),([],)], ['data'] ... ).select(sf.cardinality("data")).show() +-----------------+ |cardinality(data)| +-----------------+ | 3| | 1| | 0| +-----------------+