Python for Finance: Analyze Big Financial Data

(Elle) #1

The helper column has fulfilled its purpose and can now be deleted:


In  [ 71 ]: del es[‘DEL’]
es.info()
Out[71]: <class ‘pandas.core.frame.DataFrame’>
DatetimeIndex: 7153 entries, 1986-12-31 00:00:00 to 2014-09-26 00:00:00
Data columns (total 8 columns):
SX5P 7153 non-null float64
SX5E 7153 non-null float64
SXXP 7153 non-null float64
SXXE 7153 non-null float64
SXXF 7153 non-null float64
SXXA 7153 non-null float64
DK5F 7153 non-null float64
DKXF 7153 non-null float64
dtypes: float64(8)

Equipped with the knowledge about the structure of the EURO STOXX 50 data set, we


can also use the advanced capabilities of the read_csv function to make the import more


compact and efficient:


In  [ 72 ]: cols    =   [‘SX5P’,    ‘SX5E’, ‘SXXP’, ‘SXXE’, ‘SXXF’,
‘SXXA’, ‘DK5F’, ‘DKXF’]
es = pd.read_csv(es_url, index_col= 0 , parse_dates=True,
sep=‘;’, dayfirst=True, header=None,
skiprows= 4 , names=cols)
In [ 73 ]: es.tail()
Out[73]: SX5P SX5E SXXP SXXE SXXF SXXA DK5F
DKXF
2014-09-22 3096.02 3257.48 346.69 325.68 403.16 357.08 9703.33
564.81
2014-09-23 3057.89 3205.93 341.89 320.72 397.96 352.56 9602.32
558.35
2014-09-24 3086.12 3244.01 344.35 323.42 400.58 354.72 9628.84
559.83
2014-09-25 3059.01 3202.31 341.44 319.77 396.90 352.58 9537.95
555.51
2014-09-26 3063.71 3219.58 342.30 321.39 398.33 352.71 9558.51
556.57

Fortunately, the VSTOXX data set is already in a form such that it can be imported a bit


more easily into a DataFrame object:


In  [ 74 ]: vs  =   pd.read_csv(‘./data/vs.txt’,    index_col= 0 ,  header= 2 ,
parse_dates=True, sep=‘,’, dayfirst=True)
vs.info()
Out[74]: <class ‘pandas.core.frame.DataFrame’>
DatetimeIndex: 4010 entries, 1999-01-04 00:00:00 to 2014-09-26 00:00:00
Data columns (total 9 columns):
V2TX 4010 non-null float64
V6I1 3591 non-null float64
V6I2 4010 non-null float64
V6I3 3960 non-null float64
V6I4 4010 non-null float64
V6I5 4010 non-null float64
V6I6 3995 non-null float64
V6I7 4010 non-null float64
V6I8 3999 non-null float64
dtypes: float64(9)

Table 6-6 contains the parameters of this important import function. There are a multitude


of parameters, the majority of which default to None; object, of course, is nondefault and


has to be specified in any case.


Table 6-6. Parameters of read_csv function


Parameter Format Description
Free download pdf