質問編集履歴
1
簡潔にまとめ直しました。解答お願いします。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
to
|
1
|
+
pythonでexcelを操作したい
|
test
CHANGED
@@ -14,135 +14,9 @@
|
|
14
14
|
|
15
15
|
次のコードを打ち込んだところ下のエラー文が返されました。
|
16
16
|
|
17
|
-
```python
|
18
|
-
|
19
|
-
for i in company_name:
|
20
|
-
|
21
|
-
df_order_company = df_order[df_order['会社名'] == i]
|
22
|
-
|
23
|
-
df_order_company.to_excel(export_file_path+'/'+i+'.xlsx')
|
24
|
-
|
25
|
-
```
|
26
17
|
|
27
18
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
### エラー文
|
38
|
-
|
39
|
-
```ErrorCode
|
40
|
-
|
41
|
-
---------------------------------------------------------------------------
|
42
|
-
|
43
|
-
FileNotFoundError Traceback (most recent call last)
|
44
|
-
|
45
|
-
<ipython-input-43-f02548b0d5b0> in <module>
|
46
|
-
|
47
|
-
1 for i in company_name:
|
48
|
-
|
49
|
-
2 df_order_company = df_order[df_order['会社名'] == i]
|
50
|
-
|
51
|
-
----> 3 df_order_company.to_excel(export_file_path+'/'+i+'.xlsx')
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
c:\users\ユーザー名\appdata\local\programs\python\python38\lib\site-packages\pandas\core\generic.py in to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, encoding, inf_rep, verbose, freeze_panes)
|
56
|
-
|
57
|
-
2021 inf_rep=inf_rep,
|
58
|
-
|
59
|
-
2022 )
|
60
|
-
|
61
|
-
-> 2023 formatter.write(
|
62
|
-
|
63
|
-
2024 excel_writer,
|
64
|
-
|
65
|
-
2025 sheet_name=sheet_name,
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
c:\users\ユーザー名\appdata\local\programs\python\python38\lib\site-packages\pandas\io\formats\excel.py in write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine)
|
70
|
-
|
71
|
-
740 )
|
72
|
-
|
73
|
-
741 if need_save:
|
74
|
-
|
75
|
-
--> 742 writer.save()
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
c:\users\ユーザー名\appdata\local\programs\python\python38\lib\site-packages\pandas\io\excel\_openpyxl.py in save(self)
|
80
|
-
|
81
|
-
41 Save workbook to disk.
|
82
|
-
|
83
|
-
42 """
|
84
|
-
|
85
|
-
---> 43 return self.book.save(self.path)
|
86
|
-
|
87
|
-
44
|
88
|
-
|
89
|
-
45 @classmethod
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
c:\users\ユーザー名\appdata\local\programs\python\python38\lib\site-packages\openpyxl\workbook\workbook.py in save(self, filename)
|
94
|
-
|
95
|
-
390 if self.write_only and not self.worksheets:
|
96
|
-
|
97
|
-
391 self.create_sheet()
|
98
|
-
|
99
|
-
--> 392 save_workbook(self, filename)
|
100
|
-
|
101
|
-
393
|
102
|
-
|
103
|
-
394
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
c:\users\ユーザー名\appdata\local\programs\python\python38\lib\site-packages\openpyxl\writer\excel.py in save_workbook(workbook, filename)
|
108
|
-
|
109
|
-
289
|
110
|
-
|
111
|
-
290 """
|
112
|
-
|
113
|
-
--> 291 archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
|
114
|
-
|
115
|
-
292 writer = ExcelWriter(workbook, archive)
|
116
|
-
|
117
|
-
293 writer.save()
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
c:\users\ユーザー\appdata\local\programs\python\python38\lib\zipfile.py in __init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps)
|
122
|
-
|
123
|
-
1248 while True:
|
124
|
-
|
125
|
-
1249 try:
|
126
|
-
|
127
|
-
-> 1250 self.fp = io.open(file, filemode)
|
128
|
-
|
129
|
-
1251 except OSError:
|
130
|
-
|
131
|
-
1252 if filemode in modeDict:
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\ユーザー名\Desktop\MyPandas\output/株式会社A.xlsx'
|
136
|
-
|
137
|
-
```
|
138
|
-
|
139
|
-
### 直前までのコード
|
140
|
-
|
141
19
|
```python
|
142
|
-
|
143
|
-
!pip install openpyxl
|
144
|
-
|
145
|
-
|
146
20
|
|
147
21
|
import openpyxl
|
148
22
|
|
@@ -164,13 +38,7 @@
|
|
164
38
|
|
165
39
|
|
166
40
|
|
167
|
-
company_name = df_order['会社名'].unique()
|
41
|
+
company_name = df_order['会社名'].unique()
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
for i in company_name:
|
172
|
-
|
173
|
-
print(i)
|
174
42
|
|
175
43
|
|
176
44
|
|
@@ -178,9 +46,55 @@
|
|
178
46
|
|
179
47
|
df_order_company = df_order[df_order['会社名'] == i]
|
180
48
|
|
181
|
-
|
49
|
+
df_order_company.to_excel(export_file_path+'\'+i+'.xlsx')
|
50
|
+
|
51
|
+
|
182
52
|
|
183
53
|
```
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
**エラーコード **
|
58
|
+
|
59
|
+
```ここに言語を入力
|
60
|
+
|
61
|
+
Traceback (most recent call last):
|
62
|
+
|
63
|
+
File "script.py", line 15, in <module>
|
64
|
+
|
65
|
+
df_order_company.to_excel(export_file_path+'\'+i+'.xlsx')
|
66
|
+
|
67
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\core\generic.py", line 2023, in to_excel
|
68
|
+
|
69
|
+
formatter.write(
|
70
|
+
|
71
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\formats\excel.py", line 742, in write
|
72
|
+
|
73
|
+
writer.save()
|
74
|
+
|
75
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\excel\_openpyxl.py", line 43, in save
|
76
|
+
|
77
|
+
return self.book.save(self.path)
|
78
|
+
|
79
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\site-packages\openpyxl\workbook\workbook.py", line 392, in save
|
80
|
+
|
81
|
+
save_workbook(self, filename)
|
82
|
+
|
83
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\site-packages\openpyxl\writer\excel.py", line 291, in save_workbook
|
84
|
+
|
85
|
+
archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
|
86
|
+
|
87
|
+
File "C:\Users\ユーザー名\AppData\Local\Programs\Python\Python38\lib\zipfile.py", line 1250, in __init__
|
88
|
+
|
89
|
+
self.fp = io.open(file, filemode)
|
90
|
+
|
91
|
+
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\ユーザー名\Desktop\MyPandas\output\株式会社A.xlsx'
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
184
98
|
|
185
99
|
|
186
100
|
|