回答編集履歴
2
Update
test
CHANGED
@@ -33,8 +33,8 @@
|
|
33
33
|
ws = wb['Sheet1']
|
34
34
|
|
35
35
|
item_counts = defaultdict(int)
|
36
|
-
for i
|
36
|
+
for i, j in ws[f'A2:B{ws.max_row}']:
|
37
|
-
item_counts[i
|
37
|
+
item_counts[i.value] += j.value
|
38
38
|
item_counts = dict(item_counts)
|
39
39
|
|
40
40
|
pprint(item_counts, width=20, sort_dicts=False)
|
1
Update
test
CHANGED
@@ -21,3 +21,31 @@
|
|
21
21
|
|
22
22
|
**test_sums.xlsx**
|
23
23
|
![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-02-15/b8028994-ceae-4ebe-a8df-7581ff4e059c.png)
|
24
|
+
|
25
|
+
**追記**
|
26
|
+
|
27
|
+
```python
|
28
|
+
import openpyxl
|
29
|
+
from collections import defaultdict
|
30
|
+
from pprint import pprint
|
31
|
+
|
32
|
+
wb = openpyxl.load_workbook('test.xlsx')
|
33
|
+
ws = wb['Sheet1']
|
34
|
+
|
35
|
+
item_counts = defaultdict(int)
|
36
|
+
for i in [[i.value, j.value] for i, j in ws[f'A2:B{ws.max_row}']]:
|
37
|
+
item_counts[i[0]] += i[1]
|
38
|
+
item_counts = dict(item_counts)
|
39
|
+
|
40
|
+
pprint(item_counts, width=20, sort_dicts=False)
|
41
|
+
|
42
|
+
#
|
43
|
+
{'りんご': 2,
|
44
|
+
'みかん': 2,
|
45
|
+
'ぶどう': 2,
|
46
|
+
'柿': 2,
|
47
|
+
'いちご': 2,
|
48
|
+
'メロン': 2,
|
49
|
+
'すいか': 2,
|
50
|
+
'レモン': 2}
|
51
|
+
```
|