如何在python中使用spark笔记本上的熊猫(dashDB上的数据)

如何在python中使用spark笔记本上的熊猫(dashDB上的数据),python,pandas,ibm-cloud,dashdb,Python,Pandas,Ibm Cloud,Dashdb,您好,我正在使用IBM Bluemix。 在这里,我使用ApacheSpark笔记本并从dashDB加载数据 我试图提供一个可视化,它不显示行,只显示列 def get_file_content(credentials): from pyspark.sql import SQLContext sqlContext = SQLContext(sc) props = {} props['user'] = credentials['username'] props['password'] = c

您好,我正在使用IBM Bluemix。 在这里,我使用ApacheSpark笔记本并从dashDB加载数据 我试图提供一个可视化,它不显示行,只显示列

def get_file_content(credentials):

from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)


props = {}
props['user'] = credentials['username']
props['password'] = credentials['password']

# fill in table name
table = credentials['username'] + "." + "BATTLES"

   data_df=sqlContext.read.jdbc(credentials['jdbcurl'],table,properties=props)
data_df.printSchema()

return StringIO.StringIO(data_df)
使用此命令时:

data_df.take(5)
我通过列和行获得前5行数据的信息。 但当我这么做的时候:

content_string = get_file_content(credentials)
BATTLES_df = pd.read_table(content_string)
我得到这个错误:

ValueError:没有要从文件中分析的列

然后当我试图查看
.head()
.tail()
时,只显示列名

有人看到这里可能存在的问题吗?我对python的了解很差。谢谢你

export PYSPARK_DRIVER_PYTHON=ipython
export PYSPARK_DRIVER_PYTHON_OPTS=notebook
然后转到你的spark目录

cd ~/spark-1.6.1-bin-hadoop2.6/

./bin/pyspark --packages com.datastax.spark:spark-cassandra-connector_scalaversion:spark_version-M1
您可以编写以下代码

import pandas as pd

这是对我有效的解决方案。 我换了
BATTLES\u df=pd.read\u表(内容\u字符串)

BATTLES\u df=data\u df.toPandas()

多谢各位