{ "customer_data": [ { "name": "John Smith", "age": 35, "email": "johnsmith@gmail.com", "phone": "0413-535-124", "sales_value": [ { "year": "2022", "sales_value": 2000 }, { "year": "2023", "sales_value": 3000 } ] }, { "name": "Jane Doe", "age": 28, "email": "janedoe@yahoo.com", "phone": "0401-655-568", "sales_value": [ { "year": "2022", "sales_value": 2000 }, { "year": "2023", "sales_value": 3000 } ] }, { "name": "Bob Johnson", "age": 42, "email": "bjohnson@hotmail.com", "phone": "0433-515-912", "sales_value": [ { "year": "2022", "sales_value": 2000 }, { "year": "2023", "sales_value": 3000 } ] }, { "name": "Bob2 Johnson", "age": 42, "email": "bjohnson@hotmail.com", "phone": "0433-515-912", "sales_value": [ { "year": "2022", "sales_value": 2000 }, { "year": "2023", "sales_value": 3000 } ] }, { "name": "Bob3 Johnson", "age": 42, "email": "bjohnson@hotmail.com", "phone": "0433-515-912", "sales_value": [ { "year": "2022", "sales_value": 2000 }, { "year": "2023", "sales_value": 3000 } ] } ] }
使用上面的json文件需要在python中计算2022年的sales_value。请问你能指导我如何得到叶节点和计算2022年的总销售额吗
我已经尝试获取叶节点
1条答案
按热度按时间wgx48brx1#
如果你确定json会包含每个客户的'sales_value'字段,那么你可以尝试以下操作,这应该是不言自明的:
至于可读性较低的一个衬垫:
输出: