1 回答

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
如果我正確理解了這個(gè)問題,那么您似乎需要為每個(gè)“指標(biāo)”構(gòu)建一個(gè)字典,它將該指標(biāo)的估計(jì)值映射到其相應(yīng)的值。
rows = [
['AIDS mortality - Females', 'Rate', 'Females estimate', 'All countries', '03M49WLD', 1994, 0.110264],
['AIDS mortality - Females', 'Rate', 'Females upper estimate', 'All countries', '03M49WLD', 1994, 0.120264],
['HIV Incidence - males 15-24', 'Rate', 'Males (15-24)', 'upper estimate', 'Patigi', 'NGA_3_396', 2019, 0.00068],
['AIDS mortality - Females', 'Rate', 'Females lower estimate', 'All countries', '03M49WLD', 1994, 0.100264]
]
indicator = {}
for row in rows:
if row[0] not in indicator:
indicator[row[0]] = {}
indicator[row[0]][row[2]] = row[-1]
for key, value in indicator.items():
print(key, value)
輸出:
AIDS mortality - Females {'Females estimate': 0.110264, 'Females upper estimate': 0.120264, 'Females lower estimate': 0.100264}
HIV Incidence - males 15-24 {'Males (15-24)': 0.00068}
編輯 - 剛剛注意到示例數(shù)據(jù)中的第三行有 8 列,而其他有 7 列。您能詳細(xì)說明嗎?
添加回答
舉報(bào)