2016-11-24 52 views

回答

1

这里是我是如何能够做到这一点:

# First import the relevant libraries 
import jaydebeapi 
from ibmdbpy import IdaDataBase 
from ibmdbpy import IdaDataFrame 

创建证书哈希:

credentials_dashdb = { 
'host':'bluemix05.bluforcloud.com', 
'port':'50000', 
'user':'dash123456', 
'password':"""mypassword""", 
'database':'BLUDB' 
} 

构建连接:

dsn="DASHDB;Database=BLUDB;Hostname=" + credentials_dashdb["host"] + ";Port=50000;PROTOCOL=TCPIP;UID=" + credentials_dashdb["user"] + ";PWD=" + credentials_dashdb["password"] 
idadb=IdaDataBase(dsn) 

导入数据:

# See all the table names in the database 
df=idadb.show_tables(show_all = True) 

# Show the table names 
df.head(100) 

# create a pandas dataframe from the table, show the first few rows 
pandas_df = IdaDataFrame(idadb, 'MY_TABLE') 
pandas_df.head() 

希望能帮助别人。 Sven Hafeneger和this notebook对此解决方案有很大的贡献!

+1

你可以接受你自己的答案,如果这对你有用 –

+0

谢谢!没意识到我可以! – Matt

1

Matt,您可以放弃“导入jaydebeapi”,因为您在构建dsn时使用了dashDB ODBC驱动程序(这也是在DSX中使用ibmdbpy的推荐方式)。

链接到Sv​​en的笔记本指向R笔记本。不知道这是你的意图。无论如何,here是我的官方DSX ibmdbpy示例笔记本,它突出了您在上面描述的解决方案。