Add ability to index by label
Create a method larry.lix that can be used for label indexing like this:
lar.lix['a'] # row 'a'
lar.lix['a':] # row 'a' and everything to the right (slicing)
lar.lix[:, 'a'] # column 'a'
lar.lix['a', 'b', 'c'] # single element from 3d larry
lar.lix[['a', 'b', 'c']] # rows 'a', 'b', and 'c'
lar.lix['a':'b'] # slice
lar.lix['a':'b':2] # slice with step
Only labels and slices are allowed. Inside the function the labels will be converted to indices and then a call will be made to lar[converted_
Indexing with more than one list of labels will do rectangular indexing, not fancy indexing.
One problem with the design above: Consider the first example above but instead of 'a', let's make the
label ('a', 2). Inside getitem I won't know what that means. Because:
>> class Index(object):
....: def __init__(self):
....: pass
....: def __getitem__(self, index):
....: print index
....:
....:
>> idx = Index()
>> idx[('a', 1)]
('a', 1)
>> idx['a', 1]
('a', 1)
So to allow indexing by labels that are tuples, I'll need to change the design to:
lar.lix[:, ['a']] # column 'a'
Not as pretty.