我正在尝试从DashDB数据库中提取一些数据,并在Jupyter Notebook中对其进行分析,所有这些都在Watson Studio中。理想情况下,我们将创建一个熊猫数据框进行分析。
这是我能够做到的方式:
# 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以及此解决方案的笔记本电脑,功不可没!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句