How to select the first element of an array in a dataframe column


#1

Hello,
The element “results.address_components.short_name” is an array. I was wondering how can I select the first element of this array instead of the full array.

var DFResults2=DF_Google1.select(explode(DF_Google1 (“results”))).toDF(“results”)
var dfElements2=DFResults2.select(“results.address_components.short_name”,“results.geometry.location.lat”,“results.geometry.location.lng”)

This is what I got when I show the DF and print the sheama:

I just want the codes “30002”, “30005”… in the first element of the dataframe

Thanks in advance.


#2

Just in case someone has the same problem I had, see a couple of ways to resolve it: