I have myself a default dict like so:
dict_items([('62007459', 0), ('68092193', 0), ('40224646', 120.92999999999999), ('68078141', 0), ('68061506', 0), ('60000216', 123.84), ...])
However, I will not need all of the entries. Instead, I want to use a subset of these. I have the desired keys stored as a simple native python list
, a list of strings:
lcodes = ['40224646','60000216', ... ]
The following gives me a nice dataframe for the whole bit: (z_lookup is just a dict that matches two kinds of ids)
df_all = pd.DataFrame([(k, z_lookup.get(k, 'N/A'), v) for k, v in
output.items()], columns=['id','zcode','values'])
I can access values one at a time, for instance: output['62007459']
gives me 0
, which is correct. But I'm not sure how to scale up/iterate this process so that the pandas dataframe is only created from the keys in output
that are present in lcodes
.