On Wednesday, June 13, 2012 2:48:22 PM UTC+2, Wouter Overmeire wrote:
2012/6/13 Lorenzo De Leo
What I'm uncomfortable with is the following.
In [16]: df.reorder_levels([0,2,1]).sort_index().index
Out[16]:
MultiIndex([('bar', 0, 't1'), ('bar', 0, 't2'), ('bar', 1, 't1'),
('bar', 1, 't2'), ('foo', 0, 't3'), ('foo', 0, 't4'),
('foo', 1, 't3'), ('foo', 1, 't4')], dtype=object)
Correct me if I'm wrong. If I use method=None (the default) reindex looks for the first element of the new index, ('bar', 0, 't1') in this case, and, not finding it into the series index, gives back a nan. Fine.
But if I use method='pad', how does this comparison work? In other terms, shall I consider that ('bar', 0, 't1') and ('bar', 0, 't2') come after ('bar', 0) but before ('bar', 1) and so on? (now that I think of it, it seems quite obvious indeed)
I guess the whole thing goes wrong if I don't properly sort the index then.
In [19]: s.reindex(index=df.reorder_levels([0,2,1]).index, method='pad')
Out[19]:
first third second
bar 0 t1 -1.014172
1 t1 -1.008454
0 t2 -1.008454
1 t2 -1.008454
foo 0 t3 1.088346
1 t3 -0.845830
0 t4 -0.845830
1 t4 -0.845830
Thanks, definitely more readable.
L