October 2019
Beginner to intermediate
674 pages
16h 43m
English
The xs method provides a shortcut means of selecting data based on a particular index-level value:
In [287]: sharesIndexDF.xs('open',level='PriceType') Out[287]:
Nasdaq S&P 500 Russell 2000
TradingDate
2014/02/21 4282.17 1841.07 1166.2x5
2014/02/24 4273.32 1836.78 1166.74
2014/02/25 4298.48 1847.66 1176.00
2014/02/26 4300.45 1845.79 1176.11
2014/02/27 4291.47 1844.90 1179.28
2014/02/28 4323.52 1855.12 1189.19
6 rows × 3 columns
The more long-winded alternative to the preceding command would be to use swaplevel to switch between the TradingDate and PriceType levels and then perform the selection as follows:
In [305]: sharesIndexDF.swaplevel(0, 1, axis=0).ix['open'] Out[305]: Nasdaq S&P 500 Russell 2000 TradingDate 2014/02/21 ...
Read now
Unlock full access