I import, from a json file, the following object:
"loan_numbers":[
{"symbol":1000114, "val":0.1},
{"symbol":1000150, "val":0.15},
{"symbol":1000074, "val":0.11}
]
The above is a list of dicts.
My question is this. If i wanted to search for "symbol" (eg.1000150) and return "val" (eg. 0.15) which method would be quicker:
- [method 1] iterating through the list of dicts (for i in loan_numbers, if i['symbol']==1000150, v= val)
or
- [method 2] populate a pandas data frame and search (df.loc[df['symbol'] == 1000150, 'val'])
I was going to test both side-by-side, but was wondering if there is an accepted pythonic method or if one method was considerably faster than another under certain conditions (for example, i have a feeling that for longer lists the DataFrame would be faster because of its types).
I have done some searches, on stack overflow and also google, which show both as viable, but not which "is preferred" or why.
