Skip to content
Advertisement

SparkSQL query dataframe

I am converted a pandas dataframe into spark sql table. I am new to SQL and would like to select the key ‘code’ from table.

query

query response

How can I select the key ‘code’. The column contains a list of dict which contain the data.

Here is the rest of the code

This creates a table with following schema

enter image description here

Advertisement

Answer

The field classification is of type string so first you have to convert it to struct type, after that you can directly select as classification.code. To convert from string to struct try below.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement