How to connect a Jupyter Notebook with WRDS

Install the WRDS python module by typing in the Terminal (or Command Prompt):

pip install wrds

or (if you have an active Conda distribution - recommended):

conda install wrds

In the Jupyter Notebook, load the WRDS module and establish a connection with WRDS servers using:

import wrds
db = wrds.Connection()

Type in you WRDS username and password when asked.

Suppose you are interested in the Thomson Reuters Mutual Fund Holdings - s12 Master File. The short location of this dataset, as coded in WRDS servers, is explained in the Variable Description webpage. In this case we have that it can be accessed by loading the table S12 of the library TFN.

To get information about it, such as the names and types of the variables, type:

db.describe_table(library='tfn', table='s12')

To create a new dataframe called data with:

data = db.get_table(library='tfn', table='s12', columns=['fdate','fundname'], obs=10)

For more general queries use mySQL language. For instance:

df = db.raw_sql("select fdate, fundno "
           "from tfn.s12 "
           "where fdate between '1996-06-30' 
           and '1996-10-01'")

To close the connection with the remote database run: