Spark Dataframe column with last character of other column

前端 未结 2 1484
囚心锁ツ
囚心锁ツ 2021-01-18 02:43

I\'m looking for a way to get the last character from a string in a dataframe column and place it into another column.

I have a Spark dataframe that looks like this:

2条回答
  •  野的像风
    2021-01-18 02:57

    Just use the substring function

    from pyspark.sql.functions import substring
    df.withColumn("b", substring(col("columnName"), -1, 1))
    

提交回复
热议问题