我想創建一個字典,將項目代碼與其對應的總成本值相匹配。這些值位於不同的行和不同的列中。但是,還有其他單元可以被引用來獲取值。 Excel工作表看起來像這樣:使用python在不同的行和列中創建字典excel單元格
A B C D E
1 Project A1-234 Something Something
2 does not matter
3 Total 1234
4
5 Project A2-912 Something Something
6 also does not matter
7 another will not matter
8 Total 789
項目代碼是關鍵,總值是字典的值。根據關的,我將有2鍵值對:
dict = {
"A1-234": 1234,
"A2-912": 789
}
有很多的項目,但他們都擁有這些一致性:
什麼是創造這本字典的最佳方式?
我無法想象一個簡單的解決方案,只是一堆if語句。 (例如,如果row [0] =='Project':key = row [1]; get_total = True) –