你好,我使用的是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()
时,只显示列名。
有人看到这里可能存在的问题吗?我对蟒蛇知之甚少。求你了,谢谢你。
这是适用于我的解决方案。我更换了BATTLES_df = pd.read_table(content_string)
带有
BATTLES_df=data_df.toPandas()
谢谢
export PYSPARK_DRIVER_PYTHON=ipython
export PYSPARK_DRIVER_PYTHON_OPTS=notebook
然后转到你的火花目录
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