1
votes

I'm trying to pull some data in from a DashDB database and analyze it within a Jupyter Notebook, all within the Watson Studio. Ideally we would create a Pandas Dataframe for analysis.

2

2 Answers

1
votes

Here's how I was able to do it:

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

Create a hash with credentials:

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

Build the connection:

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

Import the data:

# 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()

Hope that helps someone. Big credit to Sven Hafeneger and this notebook for this solution!

1
votes

Matt, you can drop the "import jaydebeapi" because you are using the dashDB ODBC driver under the hood with the dsn that you construct (which is also the recommended way to use ibmdbpy in DSX).

The link to Sven's notebook points to a R notebook. Not sure if that is what you intended. In any case, here is my official DSX sample notebook for ibmdbpy that highlights the solution that you described above.