I have the following dictionary structure and Iam trying to access the total_payments
field. It is like accessing key of keys in Python dictionary:
d = {'METTS MARK': {'bonus': 600000,
'deferral_payments': 'NaN',
'deferred_income': 'NaN',
'director_fees': 'NaN',
'email_address': 'a@b.com',
'exercised_stock_options': 'NaN',
'expenses': 94299,
'from_messages': 29,
'from_poi_to_this_person': 38,
'from_this_person_to_poi': 1,
'loan_advances': 'NaN',
'long_term_incentive': 'NaN',
'other': 1740,
'poi': False,
'restricted_stock': 585062,
'restricted_stock_deferred': 'NaN',
'salary': 365788,
'shared_receipt_with_poi': 702,
'to_messages': 807,
'total_payments': 1061827,
'total_stock_value': 585062}}
Hard to read your dictionary, but there's an example:
dic = {'abc': {'123': '2'}}
print(dic['abc']['123'])
#prints 2
and if your dictionary had two sub dictionaries:
dic = {'abc': [{'123': '2'}, {'456': '4'}]}
print(dic['abc'][1]['456'])
# prints 4
in your case:
value['total_payments']
#returns 1061827
It rather seems that values of your dictionay are dict, and not that the keys are dict. So you can just access as follows:
your_dict[KEY1]['total_payments']
Please also anonymize the email address in your example.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.