pyspark.sql.functions.size#
- pyspark.sql.functions.size(col)[source]#
Collection function: returns the length of the array or map stored in the column.
Added in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters:
- col
Columnor str name of column or expression. A column that evaluates to an array or map.
- col
- Returns:
Columnlength of the array/map. Returns a column that evaluates to an integer.
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)]