[{'YEAR': 2016.0, 'DOY': 310.0, 'temperature': 12.55, 'min_temp': 10.61, 'max_temp': 14.19, 'field_id': 1, 'date': Timestamp('2016-11-05 00:00:00')}, {'YEAR': 2016.0, 'DOY': 311.0, 'temperature': 14.89, 'min_temp': 12.6, 'max_temp': 17.49, 'field_id': 1, 'date': Timestamp('2016-11-06 00:00:00')}]
In the above list of dictionaries, I want to only retain the foll. keys in this list: ['YEAR', 'temperature']
From Filter dict to contain only certain keys?, I can filter the dict to only certain keys like this:
new_dict = { your_key: old_dict[your_key] for your_key in your_keys }
-- UPDATE:
The soln should also work if a key from your_key
does not exist in the dictionary