Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Collection function: Returns the length of the array or map stored in the column.
For the corresponding Databricks SQL function, see cardinality function.
Syntax
from pyspark.sql import functions as dbf
dbf.cardinality(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Target column to compute on. |
Returns
pyspark.sql.Column: length of the array/map.
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([([1, 2, 3],),([1],),([],)], ['data'])
df.select(dbf.cardinality("data")).show()
+-----------------+
|cardinality(data)|
+-----------------+
| 3|
| 1|
| 0|
+-----------------+