pyspark.sql.functions.reverse

pyspark.sql.functions.reverse(col: ColumnOrName) → pyspark.sql.column.Column[source]

Collection function: returns a reversed string or an array with reverse order of elements.

New in version 1.5.0.

Parameters
colColumn or str

name of column or expression

Examples

>>> df = spark.createDataFrame([('Spark SQL',)], ['data'])
>>> df.select(reverse(df.data).alias('s')).collect()
[Row(s='LQS krapS')]
>>> df = spark.createDataFrame([([2, 1, 3],) ,([1],) ,([],)], ['data'])
>>> df.select(reverse(df.data).alias('r')).collect()
[Row(r=[3, 1, 2]), Row(r=[1]), Row(r=[])]