在从人口普查数据中选择并将数据放入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-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})
我正在努力让这一年有序,然后检查这些年份%是否总是在增加(如果它正在增加则返回是)。谢谢。
答案 0 :(得分:1)
您的词典结构不正确,但是,我在下面实施了正确的词典并提供了解决方案。
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}
如果您只想要一个清单:
final_data = [b['65-and-over-percent'] for a, b in data.items()]
输出:
[11.61, 6.67, 9.7]