In [10]:
#!wget https://www.dropbox.com/s//PDataFrame.py -O PDataFrame.py
import PDataFrame as pdf
#help('PDataFrame')
#!cat PDataFrame.py
The PDataFrame
class provides a persistant data frame (it is saved to a csv file on the disk). This is useful to collect information in iPython notebooks without having to add it into the notebooks itself. Use cases
Bookmarks - a notebook might rely on a number of different URL's eg to download different data series; those URL's can be stored in the notebook, but if there are too many of them then it might be cleaner to save them in a separate (and transferable!) bookmarks file
Results - when running various analysis / simulations (eg by changing the initial conditions) one might want to keep track of the results; again a PDataFrame
might be a good target for that
In [2]:
pdf.PDataFrame.create('PDataFrame.csv', ('key', 'description'))
enter data into the dataframe; this code only has to be run once, ie it can be removed afterwards; it can be run more than once without issue though, as long as the keys don't change the contents is simply overwritten
In [3]:
bm = pdf.PDataFrame('PDataFrame.csv')
bm.set('deposit', ('ILM.W.U2.C.L022.U2.EUR', 'current usage of the deposit facility'))
bm.set('lending', ('ILM.M.U2.C.A05B.U2.EUR', 'current aggregate usage of major lending facilities'))
bm.set('lending_marg', ('ILM.W.U2.C.A055.U2.EUR', 'current usage of the marginal lending facility'))
bm.set('another_one', ('NA.NA', 'lorem ipsum'))
the get
method allows to retrieve the data
In [4]:
bm.get('deposit')
Out[4]:
In [5]:
bm.get('deposit', 'key')
Out[5]:
df()
returns the underlying dataframe
In [6]:
bm = pdf.PDataFrame('PDataFrame.csv')
bm.df()
Out[6]:
rows can be deleted using delete
In [7]:
bm.delete('another_one')
In [8]:
bm = pdf.PDataFrame('PDataFrame.csv')
bm.df()
Out[8]:
In [8]: