pyspark.sql.functions.reverse¶
-
pyspark.sql.functions.
reverse
(col: ColumnOrName) → pyspark.sql.column.Column¶ Collection function: returns a reversed string or an array with reverse order of elements.
- Parameters
- col
Column
or str name of column or expression
- col
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=[])]