My spark dataframe consists of 3 columns, each of which are lists. The length of list for each row may vary. For eg my data frame would look like
I would like to be able to obtain the last element of these lists.
Expected output
There was a post to obtain the first element of the list using df = df.withColumn("First_item_Col1",df['Col1'][0])
But when I use -1 to obtain the last item in the above line, it is giving me null values