The ibmdbpy library provides a Python interface for data manipulation and access to in-database algorithms in IBM dashDB and IBM DB2. It accelerates Python analytics by seamlessly pushing operations written in Python into the underlying database for execution, thereby benefiting from in-database performance-enhancing features, such as columnar storage and parallel processing.
To get started you will need credentials for a dashDB database. If you don't already have an instance of dashDB you can get one for free by following steps in this article.
The steps outlined below are included in a tutorial notebook available on the Jupyter notebook Welcome screen of your Workbench.
Lets start by loading ibmdbPy. We will also need to import JayDeBeAPI package to connect to the database using JDBC from ibmdbPy.
import jaydebeapiNext you will need to enter your database credentials:
from ibmdbpy import IdaDataBase
from ibmdbpy import IdaDataFrame
#Enter the values for you database connectionThen create the connection:
dsn_database = "BLUDB" # e.g. "BLUDB"
dsn_hostname = "<Enter hostname>" # e.g.: "bluemix05.bluforcloud.com"
dsn_port = "50000" # e.g. "50000"
dsn_uid = "<Enter userID>" # e.g. "dash104434"
dsn_pwd = "<Enter password" # e.g. "7dBZ3jWt9xN6$o0JiX!m"
connection_string='jdbc:db2://'+dsn_hostname+':'+dsn_port+'/'+dsn_database+':user='+dsn_uid+';password='+dsn_pwd+";"Now lets read some data into a dataframe and display first 5 rows:
df=idadb.show_tables(show_all = True)The results will look like: