質問編集履歴

13

更新

2020/09/13 12:43

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -311,3 +311,85 @@
311
311
  ValueError: No objects to concatenate
312
312
 
313
313
  ```
314
+
315
+
316
+
317
+ ```python
318
+
319
+ 以下が2framesを開いたエラー表記です。
320
+
321
+
322
+
323
+ 2424 ブラス
324
+
325
+ 2018
326
+
327
+ No data
328
+
329
+ 2019
330
+
331
+ No data
332
+
333
+ ---------------------------------------------------------------------------
334
+
335
+ ValueError Traceback (most recent call last)
336
+
337
+ <ipython-input-68-b8a81eea83a2> in <module>()
338
+
339
+ 45 print(k,v)
340
+
341
+ 46 dfs = get_dfs(k)
342
+
343
+ ---> 47 data = concatenate(dfs)
344
+
345
+ 48 data.to_csv('{}-{}.csv'.format(k,v))
346
+
347
+
348
+
349
+ 2 frames
350
+
351
+ <ipython-input-68-b8a81eea83a2> in concatenate(dfs)
352
+
353
+ 29
354
+
355
+ 30 def concatenate(dfs):
356
+
357
+ ---> 31 data = pd.concat(dfs,axis=0)
358
+
359
+ 32 data = data.reset_index(drop=True)
360
+
361
+ 33 col = ['始値','高値','安値','終値','出来高','終値調整']
362
+
363
+
364
+
365
+ /usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py in concat(objs, axis, join, ignore_index, keys, levels, names, verify_integrity, sort, copy)
366
+
367
+ 279 verify_integrity=verify_integrity,
368
+
369
+ 280 copy=copy,
370
+
371
+ --> 281 sort=sort,
372
+
373
+ 282 )
374
+
375
+ 283
376
+
377
+
378
+
379
+ /usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
380
+
381
+ 327
382
+
383
+ 328 if len(objs) == 0:
384
+
385
+ --> 329 raise ValueError("No objects to concatenate")
386
+
387
+ 330
388
+
389
+ 331 if keys is None:
390
+
391
+
392
+
393
+ ValueError: No objects to concatenate
394
+
395
+ ```

12

エラーを追加しました。

2020/09/13 12:42

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -253,3 +253,61 @@
253
253
  NameError: name 'code_list' is not defined
254
254
 
255
255
  ```
256
+
257
+
258
+
259
+ ```python
260
+
261
+ 以下がエラーです。次は上のこちらの部分に赤線がひいて
262
+
263
+ ありました。→data = pd.concat(dfs,axis=0)
264
+
265
+
266
+
267
+
268
+
269
+ 2424 ブラス
270
+
271
+ 2019
272
+
273
+ No data
274
+
275
+ 2020
276
+
277
+ No data
278
+
279
+ ---------------------------------------------------------------------------
280
+
281
+ ValueError Traceback (most recent call last)
282
+
283
+ <ipython-input-67-3b125c0fc7ed> in <module>()
284
+
285
+ 45 print(k,v)
286
+
287
+ 46 dfs = get_dfs(k)
288
+
289
+ ---> 47 data = concatenate(dfs)
290
+
291
+ 48 data.to_csv('{}-{}.csv'.format(k,v))
292
+
293
+
294
+
295
+ 2 frames
296
+
297
+ /usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
298
+
299
+ 327
300
+
301
+ 328 if len(objs) == 0:
302
+
303
+ --> 329 raise ValueError("No objects to concatenate")
304
+
305
+ 330
306
+
307
+ 331 if keys is None:
308
+
309
+
310
+
311
+ ValueError: No objects to concatenate
312
+
313
+ ```

11

更新

2020/09/13 12:22

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -221,3 +221,35 @@
221
221
 
222
222
 
223
223
  ```
224
+
225
+
226
+
227
+ ```python
228
+
229
+ 以下がエラーです。
230
+
231
+ エラーが出た際、
232
+
233
+ 上のfor i in range(len(code_list)):のコードの部分に赤線が引かれていました。
234
+
235
+
236
+
237
+ NameError Traceback (most recent call last)
238
+
239
+ <ipython-input-55-b9a24c2bba32> in <module>()
240
+
241
+ 40
242
+
243
+ 41 #複数のデータフレームをcsvで保存
244
+
245
+ ---> 42 for i in range(len(code_list)):
246
+
247
+ 43 k = code_list.loc[i,'code']
248
+
249
+ 44 v = code_list.loc[i,'name']
250
+
251
+
252
+
253
+ NameError: name 'code_list' is not defined
254
+
255
+ ```

10

更新

2020/09/13 11:54

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,7 @@
52
52
 
53
53
 
54
54
 
55
- csvfile = open('/content/drive/My Drive/google cora/codelist.csv')
55
+ csvfile = open('/content/drive/My Drive/google cora/code_list.csv')
56
56
 
57
57
 
58
58
 

9

更新

2020/09/13 11:38

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -140,7 +140,7 @@
140
140
 
141
141
  #作成したコードリストを読み込む
142
142
 
143
- codelist = pd.read_csv('codelist.csv')
143
+ code_list = pd.read_csv('code_list.csv')
144
144
 
145
145
 
146
146
 

8

更新

2020/09/13 11:36

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -140,7 +140,7 @@
140
140
 
141
141
  #作成したコードリストを読み込む
142
142
 
143
- code_list = pd.read_csv('code_list.csv')
143
+ codelist = pd.read_csv('codelist.csv')
144
144
 
145
145
 
146
146
 

7

更新

2020/09/13 11:34

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -164,9 +164,11 @@
164
164
 
165
165
 
166
166
 
167
+ ```python
168
+
169
+
170
+
167
- ```以下がエラーとして出てきました。
171
+ 以下がエラーとして出てきました。
168
-
169
-
170
172
 
171
173
 
172
174
 

6

更新

2020/09/13 11:31

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -160,11 +160,15 @@
160
160
 
161
161
  data.to_csv('{}-{}.csv'.format(k,v))
162
162
 
163
-
163
+ ```
164
-
165
-
166
-
164
+
165
+
166
+
167
- 以下がエラーとして出てきました。
167
+ ```以下がエラーとして出てきました。
168
+
169
+
170
+
171
+
168
172
 
169
173
  ---------------------------------------------------------------------------
170
174
 

5

更新

2020/09/13 11:30

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -30,6 +30,10 @@
30
30
 
31
31
 
32
32
 
33
+
34
+
35
+
36
+
33
37
  ```python
34
38
 
35
39
 
@@ -207,3 +211,7 @@
207
211
 
208
212
 
209
213
  FileNotFoundError: [Errno 2] File codelist.csv does not exist: 'codelist.csv'
214
+
215
+
216
+
217
+ ```

4

現在の状況に更新しました

2020/09/13 11:27

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -48,175 +48,133 @@
48
48
 
49
49
 
50
50
 
51
- csvfile = open('/content/drive/My Drive/google cora/code_list.csv')
51
+ csvfile = open('/content/drive/My Drive/google cora/codelist.csv')
52
+
53
+
52
54
 
53
55
  reader = csv.DictReader(csvfile)
54
56
 
55
-
56
-
57
57
  for row in reader:
58
58
 
59
- print(row)
59
+ print(row)
60
+
61
+
62
+
60
-
63
+ from bs4 import BeautifulSoup
64
+
61
-
65
+ import pandas as pd
66
+
62
-
67
+ import requests
68
+
69
+ from datetime import datetime
70
+
71
+
72
+
73
+ def get_dfs(stock_number):
74
+
75
+ dfs = []
76
+
77
+ year = [2018,2019] #2017〜2019年までの株価データを取得
78
+
79
+ for y in year:
80
+
81
+ try:
82
+
83
+ print(y)
84
+
85
+ url = 'https://kabuoji3.com/stock/{}/{}/'.format(stock_number,y)
86
+
87
+ soup = BeautifulSoup(requests.get(url).content,'html.parser')
88
+
89
+ tag_tr = soup.find_all('tr')
90
+
91
+ head = [h.text for h in tag_tr[0].find_all('th')]
92
+
93
+ data = []
94
+
95
+ for i in range(1,len(tag_tr)):
96
+
97
+ data.append([d.text for d in tag_tr[i].find_all('td')])
98
+
99
+ df = pd.DataFrame(data, columns = head)
100
+
101
+
102
+
103
+ col = ['始値','高値','安値','終値','出来高','終値調整']
104
+
105
+ for c in col:
106
+
107
+ df[c] = df[c].astype(float)
108
+
109
+ df['日付'] = [datetime.strptime(i,'%Y-%m-%d') for i in df['日付']]
110
+
111
+ dfs.append(df)
112
+
113
+ except IndexError:
114
+
115
+ print('No data')
116
+
117
+ return dfs
118
+
119
+
120
+
121
+ def concatenate(dfs):
122
+
123
+ data = pd.concat(dfs,axis=0)
124
+
125
+ data = data.reset_index(drop=True)
126
+
127
+ col = ['始値','高値','安値','終値','出来高','終値調整']
128
+
129
+ for c in col:
130
+
131
+ data[c] = data[c].astype(float)
132
+
133
+ return data
134
+
135
+
136
+
137
+ #作成したコードリストを読み込む
138
+
139
+ code_list = pd.read_csv('code_list.csv')
140
+
141
+
142
+
143
+ #複数のデータフレームをcsvで保存
144
+
145
+ for i in range(len(code_list)):
146
+
147
+ k = code_list.loc[i,'code']
148
+
149
+ v = code_list.loc[i,'name']
150
+
151
+ print(k,v)
152
+
153
+ dfs = get_dfs(k)
154
+
155
+ data = concatenate(dfs)
156
+
157
+ data.to_csv('{}-{}.csv'.format(k,v))
158
+
159
+
160
+
161
+
162
+
63
- 以下が出てきたエラーです
163
+ 以下がエラーとして出てきました。
64
164
 
65
165
  ---------------------------------------------------------------------------
66
166
 
67
- UnicodeDecodeError Traceback (most recent call last)
68
-
69
- <ipython-input-6-474e9fa87ab0> in <module>()
70
-
71
- 4 reader = csv.DictReader(csvfile)
72
-
73
- 5
74
-
75
- ----> 6 for row in reader:
76
-
77
- 7 print(row)
78
-
79
-
80
-
81
- 2 frames
82
-
83
- /usr/lib/python3.6/codecs.py in decode(self, input, final)
84
-
85
- 319 # decode input (taking the buffer into account)
86
-
87
- 320 data = self.buffer + input
88
-
89
- --> 321 (result, consumed) = self._buffer_decode(data, self.errors, final)
90
-
91
- 322 # keep undecoded input until the next call
92
-
93
- 323 self.buffer = data[consumed:]
94
-
95
-
96
-
97
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 16: invalid start byte
98
-
99
-
100
-
101
- _____________________________
102
-
103
- 以上までがエラー
104
-
105
-
106
-
107
- from bs4 import BeautifulSoup
108
-
109
- import pandas as pd
110
-
111
- import requests
112
-
113
- from datetime import datetime
114
-
115
-
116
-
117
- def get_dfs(stock_number):
118
-
119
- dfs = []
120
-
121
- year = [2018,2019] #2017〜2019年までの株価データを取得
122
-
123
- for y in year:
124
-
125
- try:
126
-
127
- print(y)
128
-
129
- url = 'https://kabuoji3.com/stock/{}/{}/'.format(stock_number,y)
130
-
131
- soup = BeautifulSoup(requests.get(url).content,'html.parser')
132
-
133
- tag_tr = soup.find_all('tr')
134
-
135
- head = [h.text for h in tag_tr[0].find_all('th')]
136
-
137
- data = []
138
-
139
- for i in range(1,len(tag_tr)):
140
-
141
- data.append([d.text for d in tag_tr[i].find_all('td')])
142
-
143
- df = pd.DataFrame(data, columns = head)
144
-
145
-
146
-
147
- col = ['始値','高値','安値','終値','出来高','終値調整']
148
-
149
- for c in col:
150
-
151
- df[c] = df[c].astype(float)
152
-
153
- df['日付'] = [datetime.strptime(i,'%Y-%m-%d') for i in df['日付']]
154
-
155
- dfs.append(df)
156
-
157
- except IndexError:
158
-
159
- print('No data')
160
-
161
- return dfs
162
-
163
-
164
-
165
- def concatenate(dfs):
166
-
167
- data = pd.concat(dfs,axis=0)
168
-
169
- data = data.reset_index(drop=True)
170
-
171
- col = ['始値','高値','安値','終値','出来高','終値調整']
172
-
173
- for c in col:
174
-
175
- data[c] = data[c].astype(float)
176
-
177
- return data
178
-
179
-
180
-
181
- #作成したコードリストを読み込む
182
-
183
- code_list = pd.read_csv('code_list.csv')
184
-
185
-
186
-
187
- #複数のデータフレームをcsvで保存
188
-
189
- for i in range(len(code_list)):
190
-
191
- k = code_list.loc[i,'code']
192
-
193
- v = code_list.loc[i,'name']
194
-
195
- print(k,v)
196
-
197
- dfs = get_dfs(k)
198
-
199
- data = concatenate(dfs)
200
-
201
- data.to_csv('{}-{}.csv'.format(k,v))
202
-
203
-
204
-
205
-
206
-
207
- 以下がエラーとして出てきました。
208
-
209
167
  ---------------------------------------------------------------------------
210
168
 
211
169
  FileNotFoundError Traceback (most recent call last)
212
170
 
213
- <ipython-input-2-75c0586c9f00> in <module>()
171
+ <ipython-input-46-64a85a5b6de8> in <module>()
214
172
 
215
173
  37
216
174
 
217
175
  38 #作成したコードリストを読み込む
218
176
 
219
- ---> 39 code_list = pd.read_csv('code_list.csv')
177
+ ---> 39 codelist = pd.read_csv('codelist.csv')
220
178
 
221
179
  40
222
180
 
@@ -248,6 +206,4 @@
248
206
 
249
207
 
250
208
 
251
- FileNotFoundError: [Errno 2] File code_list.csv does not exist: 'code_list.csv'
209
+ FileNotFoundError: [Errno 2] File codelist.csv does not exist: 'codelist.csv'
252
-
253
- ```

3

画像の追加

2020/09/13 11:24

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -24,6 +24,10 @@
24
24
 
25
25
 
26
26
 
27
+ ![![イメージ説明](78084e398c508fc52913734b2396b51f.png)](0aa2c6503b87b174cf8bd61cefa8bddf.png)
28
+
29
+
30
+
27
31
 
28
32
 
29
33
  ```python

2

csvを読み込んだ際のエラーを追加しました

2020/09/13 10:22

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -28,6 +28,78 @@
28
28
 
29
29
  ```python
30
30
 
31
+
32
+
33
+ from google.colab import drive
34
+
35
+ drive.mount('/content/drive')
36
+
37
+
38
+
39
+ Mounted at /content/drive
40
+
41
+
42
+
43
+ import csv
44
+
45
+
46
+
47
+ csvfile = open('/content/drive/My Drive/google cora/code_list.csv')
48
+
49
+ reader = csv.DictReader(csvfile)
50
+
51
+
52
+
53
+ for row in reader:
54
+
55
+ print(row)
56
+
57
+
58
+
59
+ 以下が出てきたエラーです。
60
+
61
+ ---------------------------------------------------------------------------
62
+
63
+ UnicodeDecodeError Traceback (most recent call last)
64
+
65
+ <ipython-input-6-474e9fa87ab0> in <module>()
66
+
67
+ 4 reader = csv.DictReader(csvfile)
68
+
69
+ 5
70
+
71
+ ----> 6 for row in reader:
72
+
73
+ 7 print(row)
74
+
75
+
76
+
77
+ 2 frames
78
+
79
+ /usr/lib/python3.6/codecs.py in decode(self, input, final)
80
+
81
+ 319 # decode input (taking the buffer into account)
82
+
83
+ 320 data = self.buffer + input
84
+
85
+ --> 321 (result, consumed) = self._buffer_decode(data, self.errors, final)
86
+
87
+ 322 # keep undecoded input until the next call
88
+
89
+ 323 self.buffer = data[consumed:]
90
+
91
+
92
+
93
+ UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 16: invalid start byte
94
+
95
+
96
+
97
+ _____________________________
98
+
99
+ 以上までがエラー
100
+
101
+
102
+
31
103
  from bs4 import BeautifulSoup
32
104
 
33
105
  import pandas as pd

1

マークダウン記法にしました。

2020/09/13 10:15

投稿

dfmasap
dfmasap

スコア3

test CHANGED
File without changes
test CHANGED
@@ -21,6 +21,12 @@
21
21
  何も分からず恐縮ですが、ご回答いただけたら幸いです。
22
22
 
23
23
 
24
+
25
+
26
+
27
+
28
+
29
+ ```python
24
30
 
25
31
  from bs4 import BeautifulSoup
26
32
 
@@ -167,3 +173,5 @@
167
173
 
168
174
 
169
175
  FileNotFoundError: [Errno 2] File code_list.csv does not exist: 'code_list.csv'
176
+
177
+ ```