dlist is a pandas-like API for working with lists of dictionaries.
fromdlistimportdlist# initialize from a list of dictsdl=dlist([ { 'a': 1 }, { 'a': 2, 'b': 'cat' } ])
# positional indexing is list-likedl[0] # {'a': 1}dl[:2] # { 'a': 1 }, { 'a': 2, 'b': 'cat' }# access keys as attributes or string keysdl.a# [ 1, 2 ]dl('a') # ditto# make masks via all the normal operatorsdl('b') =='cat'# [ False, True ]# caseless comparison, since that's nicedl('b').caseless_eq('CAT') # [ False, True ]dl('b').isin([ 1, 'CAT'], case=False) # [ False, True ]# access things that don't exist (possibly a bad idea, but fun)dl.c# [ None, None ]# mildly fancy indexingdl[dl.a>=2] # dlist([ { 'a': 2, 'b': 'cat' } ])# assignment from a properly-sized sequencedl.c= [ True, set([1,2]) ] # dlist([ { 'a': 1, 'c': True }, { 'a': 2, 'b': 'cat', 'c': {1, 2} } ])# assignment from a non-sequencedl.d=4# dlist([ { 'a': 1, 'c': True, 'd': 4 }, { 'a': 2, 'b': 'cat', 'c': {1, 2}, 'd': 4 } ])# create a new attributedl.e= [ '1', 2 ] # dlist([{ ..., 'e': '1' }, { ..., 'e': 2 } ]) # extenddl+= [ { 'f': 5 } ] # dlist([ {...}, {...}, { 'f': 5 } ]# subtract using masksdl-= (dl.a>=2) pandas wants to aggressively type everything. I like the flexibility of dictionaries. I suppose I could dtype=object and get most of this, but that felt icky.
Sure, something like this probably already exists. Also, maybe it's not even a good idea. But it was fun to make.