質問編集履歴
1
「コードの挿入」を使っていなかったので、直しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
PWMという名前のディレクトリに約400個のテキストファイルがあります。
|
3
|
+
PWM_VitroDB+PSP_b=√Nという名前のディレクトリに約400個のテキストファイルがあります。
|
4
4
|
|
5
5
|
それらすべてをデータフレームとして読み込むところまではできています。
|
6
6
|
|
@@ -14,13 +14,15 @@
|
|
14
14
|
|
15
15
|
|
16
16
|
|
17
|
+
```
|
18
|
+
|
17
19
|
from glob import glob
|
18
20
|
|
19
21
|
import pandas as pd
|
20
22
|
|
21
23
|
|
22
24
|
|
23
|
-
files=glob("PWM/*.txt")
|
25
|
+
files=glob("PWM_VitroDB+PSP_b=√N/*.txt")
|
24
26
|
|
25
27
|
|
26
28
|
|
@@ -30,6 +32,8 @@
|
|
30
32
|
|
31
33
|
df[a]=pd.read_table(file,header=None)
|
32
34
|
|
35
|
+
```
|
36
|
+
|
33
37
|
|
34
38
|
|
35
39
|
### コメント
|
@@ -49,3 +53,223 @@
|
|
49
53
|
説明が分かりにくかったらすみません。
|
50
54
|
|
51
55
|
よろしくお願いします。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
### Error
|
60
|
+
|
61
|
+
(長くてすみません…)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
KeyError Traceback (most recent call last)
|
68
|
+
|
69
|
+
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
|
70
|
+
|
71
|
+
2896 try:
|
72
|
+
|
73
|
+
-> 2897 return self._engine.get_loc(key)
|
74
|
+
|
75
|
+
2898 except KeyError:
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
KeyError: 14
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
During handling of the above exception, another exception occurred:
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
KeyError Traceback (most recent call last)
|
104
|
+
|
105
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in set(self, item, value)
|
106
|
+
|
107
|
+
1068 try:
|
108
|
+
|
109
|
+
-> 1069 loc = self.items.get_loc(item)
|
110
|
+
|
111
|
+
1070 except KeyError:
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
|
116
|
+
|
117
|
+
2898 except KeyError:
|
118
|
+
|
119
|
+
-> 2899 return self._engine.get_loc(self._maybe_cast_indexer(key))
|
120
|
+
|
121
|
+
2900 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
KeyError: 14
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
During handling of the above exception, another exception occurred:
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
ValueError Traceback (most recent call last)
|
150
|
+
|
151
|
+
<ipython-input-73-82b18bb0ee6f> in <module>
|
152
|
+
|
153
|
+
6 for file in files:
|
154
|
+
|
155
|
+
7 a=files.index(file)
|
156
|
+
|
157
|
+
----> 8 df[a]=pd.read_table(file,header=None)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in __setitem__(self, key, value)
|
162
|
+
|
163
|
+
3470 else:
|
164
|
+
|
165
|
+
3471 # set column
|
166
|
+
|
167
|
+
-> 3472 self._set_item(key, value)
|
168
|
+
|
169
|
+
3473
|
170
|
+
|
171
|
+
3474 def _setitem_slice(self, key, value):
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
~\Anaconda3\lib\site-packages\pandas\core\frame.py in _set_item(self, key, value)
|
176
|
+
|
177
|
+
3548 self._ensure_valid_index(value)
|
178
|
+
|
179
|
+
3549 value = self._sanitize_column(key, value)
|
180
|
+
|
181
|
+
-> 3550 NDFrame._set_item(self, key, value)
|
182
|
+
|
183
|
+
3551
|
184
|
+
|
185
|
+
3552 # check if we are modifying a copy
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
~\Anaconda3\lib\site-packages\pandas\core\generic.py in _set_item(self, key, value)
|
190
|
+
|
191
|
+
3379
|
192
|
+
|
193
|
+
3380 def _set_item(self, key, value):
|
194
|
+
|
195
|
+
-> 3381 self._data.set(key, value)
|
196
|
+
|
197
|
+
3382 self._clear_item_cache()
|
198
|
+
|
199
|
+
3383
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in set(self, item, value)
|
204
|
+
|
205
|
+
1070 except KeyError:
|
206
|
+
|
207
|
+
1071 # This item wasn't present, just insert at end
|
208
|
+
|
209
|
+
-> 1072 self.insert(len(self.items), item, value)
|
210
|
+
|
211
|
+
1073 return
|
212
|
+
|
213
|
+
1074
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\managers.py in insert(self, loc, item, value, allow_duplicates)
|
218
|
+
|
219
|
+
1179 new_axis = self.items.insert(loc, item)
|
220
|
+
|
221
|
+
1180
|
222
|
+
|
223
|
+
-> 1181 block = make_block(values=value, ndim=self.ndim, placement=slice(loc, loc + 1))
|
224
|
+
|
225
|
+
1182
|
226
|
+
|
227
|
+
1183 for blkno, count in _fast_count_smallints(self._blknos[loc:]):
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py in make_block(values, placement, klass, ndim, dtype, fastpath)
|
232
|
+
|
233
|
+
3265 values = DatetimeArray._simple_new(values, dtype=dtype)
|
234
|
+
|
235
|
+
3266
|
236
|
+
|
237
|
+
-> 3267 return klass(values, ndim=ndim, placement=placement)
|
238
|
+
|
239
|
+
3268
|
240
|
+
|
241
|
+
3269
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py in __init__(self, values, placement, ndim)
|
246
|
+
|
247
|
+
2773 values = np.array(values, dtype=object)
|
248
|
+
|
249
|
+
2774
|
250
|
+
|
251
|
+
-> 2775 super().__init__(values, ndim=ndim, placement=placement)
|
252
|
+
|
253
|
+
2776
|
254
|
+
|
255
|
+
2777 @property
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
~\Anaconda3\lib\site-packages\pandas\core\internals\blocks.py in __init__(self, values, placement, ndim)
|
260
|
+
|
261
|
+
126 raise ValueError(
|
262
|
+
|
263
|
+
127 "Wrong number of items passed {val}, placement implies "
|
264
|
+
|
265
|
+
--> 128 "{mgr}".format(val=len(self.values), mgr=len(self.mgr_locs))
|
266
|
+
|
267
|
+
129 )
|
268
|
+
|
269
|
+
130
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
ValueError: Wrong number of items passed 14, placement implies 1
|
274
|
+
|
275
|
+
```
|