numpy - Python + Pandas + Spark - How to import a dataframe into Pandas dataframe and convert it into a dictionary? -
how can import dataframe pandas dataframe , convert dictionary?
i have dataframe created spark,
sc = sparkcontext(appname="pythonsql") sqlcontext = sqlcontext(sc) path = os.path.join(os.environ['spark_home'], "examples/src/main/resources/people.json") # create dataframe df = sqlcontext.read.json(path) # register dataframe table. df.registertemptable("people") # sql statements can run using sql methods provided sqlcontext teenagers = sqlcontext.sql("select name people") sc.stop()
when try import pandas,
teenagers = pd.dataframe(teenagers, columns=['name'])
i error,
[client 127.0.0.1:50885] pandaserror: dataframe constructor not called!
after all, want convert dataframe dictionary,
dict = teenagers.set_index('name').to_dict() print dict
any ideas?
a spark dataframe can converted pandas dataframe topandas
method.
Comments
Post a Comment