http://stackoverflow.com/questions/22636487/selection-in-multi-indexed-dataframe-when-key-does-not-exists/22637762#22637762
In [23]: df = DataFrame({'a':[1,2,3],'b':[1,2,3],'c':[1,2,3]})
In [24]: x = df.set_index(['a','b'])
In [25]: x
Out[25]:
c
a b
1 1 1
2 2 2
3 3 3
[3 rows x 1 columns]
In [26]: x.T.get((1,1))
Out[26]:
c 1
Name: (1, 1), dtype: int64
In [27]: x.T.get((1,5),default='foo')
Out[27]: 'foo'
x.get((1,5),default='foo',axis=0)
should work (still need the info_axis
to be the default though)
Comment From: jreback
I suppose this could be added as an argument to loc, e.g. default
(and handled on missing inputs), though .fillna
really does this nicely.