title: SparkSQL query dataframe
body: <p>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. </p>
  
  <p>query</p>
  
  <pre><code>sqlContext.sql("""SELECT `classification` FROM psyc""").show()
  </code></pre>
  
  <p>query response</p>
  
  <pre><code>+--------------------+
  |      classification|
  +--------------------+
  |[{'code': '3297',...|
  |[{'code': '3410',...|
  |[{'code': '3410',...|
  |[{'code': '2227',...|
  |[{'code': '3410',...|
  +--------------------+
  </code></pre>
  
  <p>How can I select the key 'code'. The column contains a list of dict which contain the data. </p>
  
  <pre><code> sqlContext.sql("""SELECT `classification.code` FROM psyc""").show() # this query does not work
  </code></pre>
  
  <p>Here is the rest of the code</p>
  
  <pre><code>from pyspark.sql import SparkSession
  from pyspark.sql import SQLContext
  
  spark = SparkSession \
      .builder \
      .appName("Python Spark SQL ") \
      .getOrCreate()
  
  sc = spark.sparkContext                       
  sqlContext = SQLContext(sc)
  
  fp = os.path.join(BASE_DIR,'psyc.csv')
  df = spark.read.csv(fp,header=True)
  df.printSchema()
  df.createOrReplaceTempView("psyc")
  </code></pre>
  
  <p>This creates a table with following schema</p>
  
  <p><a href="https://i.stack.imgur.com/GtXta.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GtXta.png" alt="enter image description here"></a></p>