pyspark.sql.functions.length#
- pyspark.sql.functions.length(col)[source]#
Computes the character length of string data or number of bytes of binary data. The length of character data includes the trailing spaces. The length of binary data includes binary zeros.
Added in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters:
- col
Columnor column name target column to work on. A column that evaluates to a string or binary.
- col
- Returns:
Columnlength of the value. Returns a column that evaluates to an integer.
Examples
>>> from pyspark.sql import functions as sf >>> spark.createDataFrame([('ABC ',)], ['a']).select('*', sf.length('a')).show() +----+---------+ | a|length(a)| +----+---------+ |ABC | 4| +----+---------+