title: Python + Pandas + Spark - How to import a dataframe into Pandas dataframe and convert it into a dictionary?
body: <p>How can I import a dataframe into Pandas dataframe and convert it into a dictionary?</p>
  
  <p>I have this dataframe created from Spark,</p>
  
  <pre><code>sc = SparkContext(appName="PythonSQL")
      sqlContext = SQLContext(sc)
  
      path = os.path.join(os.environ['SPARK_HOME'], "examples/src/main/resources/people.json")
  
  # Create the DataFrame
  df = sqlContext.read.json(path)
  
  # Register this DataFrame as a table.
  df.registerTempTable("people")
  
  # SQL statements can be run by using the sql methods provided by sqlContext
  teenagers = sqlContext.sql("SELECT name FROM people")
  
  sc.stop()
  </code></pre>
  
  <p>When I try to import it into Pandas,</p>
  
  <pre><code>teenagers = pd.DataFrame(teenagers, columns=['name'])
  </code></pre>
  
  <p>I get this error,</p>
  
  <blockquote>
    <p>[client 127.0.0.1:50885] PandasError: DataFrame constructor not
    properly called!</p>
  </blockquote>
  
  <p>After all, I just want to convert the dataframe into a dictionary,</p>
  
  <pre><code>dict = teenagers.set_index('name').to_dict()
  print dict
  </code></pre>
  
  <p>Any ideas?</p>