質問編集履歴

1

行う趣旨、コードの追加

2020/10/22 09:36

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,8 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
+ Excelの自動化
4
+
3
- エラー解消
5
+ 集計表作成
4
6
 
5
7
 
6
8
 
@@ -12,13 +14,37 @@
12
14
 
13
15
  ### 該当のソースコード
14
16
 
17
+ Python
18
+
19
+ import pandas as pd
20
+
21
+ df = pd.read_excel("店舗別売上リスト.xlsx",sheet_name="統合表")
22
+
23
+ shopDictionary = {}
24
+
25
+ total = 0 #全店舗の売上を保存する変数
26
+
27
+ for index,rows in df.iterrows():
28
+
29
+ if rows["店名"] not in shopDictionary:
30
+
31
+ shopDictionary[rows["店名"]] = rows["売上金額"]
32
+
33
+ else:
34
+
35
+ shopDictionary[rows["店名"]] = shopDictionary[rows["店名"]] + rows["売上金額"]
36
+
37
+ total = total + rows["売上金額"]
38
+
39
+ shopDictionary["全店合計"] = total
40
+
41
+ df2 = pd.DataFrame(list(shopDictionary.items()),columns=["店名","売上合計"])
15
42
 
16
43
 
17
- ```ここに言語名を入力
18
44
 
19
- ソーコード
45
+ with pd.ExcelWriter("店舗別売上集計リト.xlsx",date_format='YYYY/MM/DD',datetime_format='YYYY/MM/DD') as writer:
20
46
 
21
- ```
47
+ df2.to_excel(writer, sheet_name="集計表",index=False)
22
48
 
23
49
 
24
50
 
@@ -37,3 +63,5 @@
37
63
  Python 3.8.6
38
64
 
39
65
  VScode
66
+
67
+ pyenvでインストール