pyspark.sql.functions.size

pyspark.sql.functions.size(col: ColumnOrName) → pyspark.sql.column.Column

Collection function: returns the length of the array or map stored in the column.

Parameters
colColumn or str

name of column or expression

Examples

>>> df = spark.createDataFrame([([1, 2, 3],),([1],),([],)], ['data'])
>>> df.select(size(df.data)).collect()
[Row(size(data)=3), Row(size(data)=1), Row(size(data)=0)]