質問編集履歴

6

コード文へ修正

2020/10/14 15:00

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -43,6 +43,10 @@
43
43
 
44
44
 
45
45
  ###起きているエラー全文
46
+
47
+
48
+
49
+ ```ここに言語を入力
46
50
 
47
51
  ---------------------------------------------------------------------------
48
52
 
@@ -158,6 +162,8 @@
158
162
 
159
163
 
160
164
 
165
+ ```
166
+
161
167
  というエラーが出て、うまく処理ができません。
162
168
 
163
169
  Keyerrorは辞書型データを利用している時に出てしまうそうなのですが、今回は辞書型データを使っているつもりがなく、、

5

エラーを全文に変更

2020/10/14 15:00

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -42,9 +42,117 @@
42
42
 
43
43
 
44
44
 
45
- ###起きているエラー
45
+ ###起きているエラー全文
46
46
 
47
+ ---------------------------------------------------------------------------
48
+
47
- KeyError Traceback (most recent call last)
49
+ KeyError Traceback (most recent call last)
50
+
51
+ ~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
52
+
53
+ 2645 try:
54
+
55
+ -> 2646 return self._engine.get_loc(key)
56
+
57
+ 2647 except KeyError:
58
+
59
+
60
+
61
+ pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
62
+
63
+
64
+
65
+ pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
66
+
67
+
68
+
69
+ pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
70
+
71
+
72
+
73
+ pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
74
+
75
+
76
+
77
+ KeyError: 1
78
+
79
+
80
+
81
+ During handling of the above exception, another exception occurred:
82
+
83
+
84
+
85
+ KeyError Traceback (most recent call last)
86
+
87
+ <ipython-input-81-e3c29a94a9bc> in <module>
88
+
89
+ 2 list_dayofweek=[]
90
+
91
+ 3 for i in range(len(datetime)):
92
+
93
+ ----> 4 list_dayofweek.append(datetime[i].strftime("%A"))
94
+
95
+ 5 list_dayofweek
96
+
97
+
98
+
99
+ ~\Anaconda3\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
100
+
101
+ 869 key = com.apply_if_callable(key, self)
102
+
103
+ 870 try:
104
+
105
+ --> 871 result = self.index.get_value(self, key)
106
+
107
+ 872
108
+
109
+ 873 if not is_scalar(result):
110
+
111
+
112
+
113
+ ~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
114
+
115
+ 4386 # try that
116
+
117
+ 4387 try:
118
+
119
+ -> 4388 iloc = self.get_loc(key)
120
+
121
+ 4389 return s[iloc]
122
+
123
+ 4390 except KeyError:
124
+
125
+
126
+
127
+ ~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
128
+
129
+ 2646 return self._engine.get_loc(key)
130
+
131
+ 2647 except KeyError:
132
+
133
+ -> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
134
+
135
+ 2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
136
+
137
+ 2650 if indexer.ndim > 1 or indexer.size > 1:
138
+
139
+
140
+
141
+ pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
142
+
143
+
144
+
145
+ pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
146
+
147
+
148
+
149
+ pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
150
+
151
+
152
+
153
+ pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
154
+
155
+
48
156
 
49
157
  KeyError: 1
50
158
 

4

回答いただいた内容を追記

2020/10/14 14:59

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -11,6 +11,26 @@
11
11
  list_dayofweek.append(dayofweek)
12
12
 
13
13
  list_dayofweek
14
+
15
+ ```
16
+
17
+
18
+
19
+ ###修正後でまだエラーが出ているコード
20
+
21
+ ```ここに言語を入力
22
+
23
+ datetime=analysis_data["datetime"]
24
+
25
+ list_dayofweek=[]
26
+
27
+ for i in range(len(datetime)):
28
+
29
+ list_dayofweek.append(datetime[i].strftime("%A"))
30
+
31
+ list_dayofweek
32
+
33
+
14
34
 
15
35
  ```
16
36
 

3

dayofweekの位置を修正

2020/10/14 14:56

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  for i in range(len(analysis_data["datetime"])):
8
8
 
9
- analysis_data["datetime"][i].strftime("%A")=dayofweek
9
+ dayofweek=analysis_data["datetime"][i].strftime("%A")
10
10
 
11
11
  list_dayofweek.append(dayofweek)
12
12
 

2

dayofweekを追加しました。

2020/10/14 14:35

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  for i in range(len(analysis_data["datetime"])):
8
8
 
9
- analysis_data["datetime"][i].strftime("%A")
9
+ analysis_data["datetime"][i].strftime("%A")=dayofweek
10
10
 
11
11
  list_dayofweek.append(dayofweek)
12
12
 

1

<code>へ変更

2020/10/14 14:33

投稿

Ryota0918
Ryota0918

スコア15

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
1
  ###エラーが起きているコード
2
+
3
+ ```ここに言語を入力
2
4
 
3
5
  list_dayofweek=[]
4
6
 
@@ -9,6 +11,8 @@
9
11
  list_dayofweek.append(dayofweek)
10
12
 
11
13
  list_dayofweek
14
+
15
+ ```
12
16
 
13
17
 
14
18