pydata/pandas — pull request #3280 by y-p (2013-04-08 11:29:06+00:00)
Title: ENH: add to_series() method to Index and subclasses GH3275

#3275

```python
In [10]: df=mkdf(10,5,r_idx_nlevels=2)

In [11]: df.index
Out[11]:
MultiIndex
[R_l0_g0 R_l1_g0, R_l0_g1 R_l1_g1, R_l0_g2 R_l1_g2, R_l0_g3 R_l1_g3, R_l0_g4 R_l1_g4, R_l0_g5 R_l1_g5, R_l0_g6 R_l1_g6, R_l0_g7 R_l1_g7, R_l0_g8 R_l1_g8, R_l0_g9 R_l1_g9]

In [12]: # new method
...: df.index.to_series()
Out[12]:
R0 R1
R_l0_g0 R_l1_g0 (R_l0_g0, R_l1_g0)
R_l0_g1 R_l1_g1 (R_l0_g1, R_l1_g1)
R_l0_g2 R_l1_g2 (R_l0_g2, R_l1_g2)
R_l0_g3 R_l1_g3 (R_l0_g3, R_l1_g3)
R_l0_g4 R_l1_g4 (R_l0_g4, R_l1_g4)
R_l0_g5 R_l1_g5 (R_l0_g5, R_l1_g5)
R_l0_g6 R_l1_g6 (R_l0_g6, R_l1_g6)
R_l0_g7 R_l1_g7 (R_l0_g7, R_l1_g7)
R_l0_g8 R_l1_g8 (R_l0_g8, R_l1_g8)
R_l0_g9 R_l1_g9 (R_l0_g9, R_l1_g9)
dtype: object

In [13]: # so now this is possible
...: df[df.index.to_series().map(lambda x: "4" in x[0])]
Out[13]:
C0 C_l0_g0 C_l0_g1 C_l0_g2 C_l0_g3 C_l0_g4
R0 R1
R_l0_g4 R_l1_g4 R4C0 R4C1 R4C2 R4C3 R4C4
```