Download the Jupyter Notebook for this section: data.ipynb

Loading Data Example

[1]:
import pyblp

pyblp.__version__
[1]:
'1.1.0'

Any number of functions can be used to load the example data into memory. In this example, we’ll first use NumPy.

[2]:
import numpy as np
blp_product_data = np.recfromcsv(pyblp.data.BLP_PRODUCTS_LOCATION, encoding='utf-8')
blp_agent_data = np.recfromcsv(pyblp.data.BLP_AGENTS_LOCATION, encoding='utf-8')

Record arrays can be cumbersome to manipulate. A more flexible alternative is the pandas DataFrame. Unlike NumPy, pyblp does not directly depend on pandas, but it can be useful when manipulating data.

[3]:
import pandas as pd
blp_product_data = pd.read_csv(pyblp.data.BLP_PRODUCTS_LOCATION)
blp_agent_data = pd.read_csv(pyblp.data.BLP_AGENTS_LOCATION)

Another benefit of DataFrame objects is that they display nicely in Jupyter notebooks.

[4]:
blp_product_data.head()
[4]:
market_ids clustering_ids car_ids firm_ids region shares prices hpwt air mpd ... supply_instruments2 supply_instruments3 supply_instruments4 supply_instruments5 supply_instruments6 supply_instruments7 supply_instruments8 supply_instruments9 supply_instruments10 supply_instruments11
0 1971 AMGREM71 129 15 US 0.001051 4.935802 0.528997 0 1.888146 ... 0.0 1.705933 1.595656 87.0 -61.959985 0.0 46.060389 29.786989 0.0 1.888146
1 1971 AMHORN71 130 15 US 0.000670 5.516049 0.494324 0 1.935989 ... 0.0 1.680910 1.490295 87.0 -61.959985 0.0 46.060389 29.786989 0.0 1.935989
2 1971 AMJAVL71 132 15 US 0.000341 7.108642 0.467613 0 1.716799 ... 0.0 1.801067 1.357703 87.0 -61.959985 0.0 46.060389 29.786989 0.0 1.716799
3 1971 AMMATA71 134 15 US 0.000522 6.839506 0.426540 0 1.687871 ... 0.0 1.818061 1.261347 87.0 -61.959985 0.0 46.060389 29.786989 0.0 1.687871
4 1971 AMAMBS71 136 15 US 0.000442 8.928395 0.452489 0 1.504286 ... 0.0 1.933210 1.237365 87.0 -61.959985 0.0 46.060389 29.786989 0.0 1.504286

5 rows × 33 columns

[5]:
blp_agent_data.head()
[5]:
market_ids weights nodes0 nodes1 nodes2 nodes3 nodes4 income
0 1971 0.000543 1.192188 0.478777 0.980830 -0.824410 2.473301 109.560369
1 1971 0.000723 1.497074 -2.026204 -1.741316 1.412568 -0.747468 45.457314
2 1971 0.000544 1.438081 0.813280 -1.749974 -1.203509 0.049558 127.146548
3 1971 0.000701 1.768655 -0.177453 0.286602 0.391517 0.683669 22.604045
4 1971 0.000549 0.849970 -0.135337 0.735920 1.036247 -1.143436 170.226032

This tutorial demonstrates how the instruments included in this dataset can be constructed from scratch.