Python 如何找到dict中的递增值?
在从人口普查数据中选择数据并将其输入dict后,我有:Python 如何找到dict中的递增值?,python,Python,在从人口普查数据中选择数据并将其输入dict后,我有: data = {'1991': {'0-to-14-percent': 20.85, 'year': '1991', '0-to-14 count': 5692555.0, '65-and-over-count': 3169970.0, '65-and-over-percent': 11.61, '15-to-64-count': 18434335.0, 'total-count': 27296860.0, '15-to-64-percen
data = {'1991': {'0-to-14-percent': 20.85, 'year': '1991', '0-to-14 count': 5692555.0, '65-and-over-count': 3169970.0, '65-and-over-percent': 11.61, '15-to-64-count': 18434335.0, 'total-count': 27296860.0, '15-to-64-percent': 67.53}, '1981': {'0-to-14-percent': 22.52, 'year': '1981', '0-to-14 count': 5481100.0, '65-and-over-count': 2360975.0, '65-and-over-percent': 9.7, '15-to-64-count': 16501100.0, 'total-count': 24343175.0, '15-to-64-percent': 67.79}, '1941': {'0-to-14-percent': 27.8, 'year': '1941', '0-to-14 count': 3198551.0, '65-and-over-count': 767815.0, '65-and-over-percent': 6.67, '15-to-64-count': 7540289.0, 'total-count': 11506655.0, '15-to-64-percent': 65.53}, ('1941', {'0-to-14-percent': 27.8, 'year': '1941', '0-to-14 count': 3198551.0, '65-and-over-count': 767815.0, '65-and-over-percent': 6.67, '15-to-64-count': 7540289.0, 'total-count': 11506655.0, '15-to-64-percent': 65.53})
我正在尝试整理年份,然后检查百分比在这些年份中是否一直在增加(如果增加,则返回Yes)。多谢各位 您的字典结构不正确,但是,我在下面实现了正确的字典并提供了解决方案
data = {'1991': {'0-to-14-percent': 20.85, 'year': '1991', '0-to-14 count': 5692555.0, '65-and-over-count': 3169970.0, '65-and-over-percent': 11.61, '15-to-64-count': 18434335.0, 'total-count': 27296860.0, '15-to-64-percent': 67.53}, '1981': {'0-to-14-percent': 22.52, 'year': '1981', '0-to-14 count': 5481100.0, '65-and-over-count': 2360975.0, '65-and-over-percent': 9.7, '15-to-64-count': 16501100.0, 'total-count': 24343175.0, '15-to-64-percent': 67.79}, '1941': {'0-to-14-percent': 27.8, 'year': '1941', '0-to-14 count': 3198551.0, '65-and-over-count': 767815.0, '65-and-over-percent': 6.67, '15-to-64-count': 7540289.0, 'total-count': 11506655.0, '15-to-64-percent': 65.53}, '1941':{'0-to-14-percent': 27.8, 'year': '1941', '0-to-14 count': 3198551.0, '65-and-over-count': 767815.0, '65-and-over-percent': 6.67, '15-to-64-count': 7540289.0, 'total-count': 11506655.0, '15-to-64-percent': 65.53}}
final_data = {a:b['65-and-over-percent'] for a, b in data.items()}
输出:
{'1991': 11.61, '1941': 6.67, '1981': 9.7}
[11.61, 6.67, 9.7]
如果您只需要一个列表:
final_data = [b['65-and-over-percent'] for a, b in data.items()]
输出:
{'1991': 11.61, '1941': 6.67, '1981': 9.7}
[11.61, 6.67, 9.7]
谢谢,对不起,我的问题不对,所以我只是编辑了一下。我在找%