質問するログイン新規登録

質問編集履歴

2

エラー解決(行指定エラー)のため、更新しておきます。

2019/03/01 01:08

投稿

shu_magi
shu_magi

スコア19

title CHANGED
File without changes
body CHANGED
@@ -44,118 +44,4 @@
44
44
 
45
45
  ### 実施イメージ
46
46
 
47
- 別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
47
+ 別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
48
-
49
- ### 【追記】発生している問題・エラーメッセージ
50
- 以下プログラムを実行しましたが、エラーがでて処理が完了しません。
51
- test_datav03の21列目に、反映結果のデータを入れたいと考えています。
52
- list_test.csvが定義テーブルのデータです。
53
-
54
- ```Python
55
- import numpy as np
56
- import pandas as pd
57
-
58
- #csvを読み込み
59
- df = pd.read_csv("testdata_v03.csv", header=0)
60
-
61
- print(df)
62
-
63
- df_ref = pd.read_csv("list_test.csv", header=0)
64
-
65
- df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
66
- (df_ref.values[:, 2] >= x.values[9]) &
67
- (df_ref.values[:, 3] <= x.values[10]) &
68
- (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
69
-
70
- print(df)
71
-
72
- ```
73
-
74
- 以下エラーがでています。
75
- ---------------------------------------------------------------------------
76
- IndexError Traceback (most recent call last)
77
- <ipython-input-3-4a0b1b44785f> in <module>()
78
- 9 df_ref = pd.read_csv("area_list_test.csv", header=0)
79
- 10
80
- ---> 11 df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
81
- 12 (df_ref.values[:, 2] >= x.values[9]) &
82
- 13 (df_ref.values[:, 3] <= x.values[10]) &
83
-
84
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
85
- 6012 args=args,
86
- 6013 kwds=kwds)
87
- -> 6014 return op.get_result()
88
- 6015
89
- 6016 def applymap(self, func):
90
-
91
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
92
- 316 *self.args, **self.kwds)
93
- 317
94
- --> 318 return super(FrameRowApply, self).get_result()
95
- 319
96
- 320 def apply_broadcast(self):
97
-
98
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
99
- 140 return self.apply_raw()
100
- 141
101
- --> 142 return self.apply_standard()
102
- 143
103
- 144 def apply_empty_result(self):
104
-
105
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_standard(self)
106
- 246
107
- 247 # compute the result using the series generator
108
- --> 248 self.apply_series_generator()
109
- 249
110
- 250 # wrap results
111
-
112
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_series_generator(self)
113
- 275 try:
114
- 276 for i, v in enumerate(series_gen):
115
- --> 277 results[i] = self.f(v)
116
- 278 keys.append(v.name)
117
- 279 except Exception as e:
118
-
119
- <ipython-input-3-4a0b1b44785f> in <lambda>(x)
120
- 12 (df_ref.values[:, 2] >= x.values[9]) &
121
- 13 (df_ref.values[:, 3] <= x.values[10]) &
122
- ---> 14 (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
123
- 15
124
- 16 print(df)
125
-
126
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
127
- 1470 except (KeyError, IndexError):
128
- 1471 pass
129
- -> 1472 return self._getitem_tuple(key)
130
- 1473 else:
131
- 1474 # we by definition only have the 0th axis
132
-
133
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
134
- 2011 def _getitem_tuple(self, tup):
135
- 2012
136
- -> 2013 self._has_valid_tuple(tup)
137
- 2014 try:
138
- 2015 return self._getitem_lowerdim(tup)
139
-
140
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
141
- 220 raise IndexingError('Too many indexers')
142
- 221 try:
143
- --> 222 self._validate_key(k, i)
144
- 223 except ValueError:
145
- 224 raise ValueError("Location based indexing can only have "
146
-
147
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
148
- 1955 return
149
- 1956 elif is_integer(key):
150
- -> 1957 self._validate_integer(key, axis)
151
- 1958 elif isinstance(key, tuple):
152
- 1959 # a tuple should already have been caught by this point
153
-
154
- ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
155
- 2007 l = len(ax)
156
- 2008 if key >= l or key < -l:
157
- -> 2009 raise IndexError("single positional indexer is out-of-bounds")
158
- 2010
159
- 2011 def _getitem_tuple(self, tup):
160
-
161
- IndexError: ('single positional indexer is out-of-bounds', 'occurred at index 0')

1

プログラムを実際のテストファイルで実装したところ、エラーがでたため、その部分を追記しました。

2019/03/01 01:08

投稿

shu_magi
shu_magi

スコア19

title CHANGED
File without changes
body CHANGED
@@ -42,6 +42,120 @@
42
42
  |5|139|39|**8**|
43
43
 
44
44
 
45
- ### 発生している問題・エラーッセージ
45
+ ### 実施イメージ
46
46
 
47
- 別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
47
+ 別テーブルの条件(x1, x2, y1, y2)を参照し、データテーブルのx, yがそのうちどの区間に入っているか判別、対応するarea列の値を返す、ことをしたいです。
48
+
49
+ ### 【追記】発生している問題・エラーメッセージ
50
+ 以下プログラムを実行しましたが、エラーがでて処理が完了しません。
51
+ test_datav03の21列目に、反映結果のデータを入れたいと考えています。
52
+ list_test.csvが定義テーブルのデータです。
53
+
54
+ ```Python
55
+ import numpy as np
56
+ import pandas as pd
57
+
58
+ #csvを読み込み
59
+ df = pd.read_csv("testdata_v03.csv", header=0)
60
+
61
+ print(df)
62
+
63
+ df_ref = pd.read_csv("list_test.csv", header=0)
64
+
65
+ df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
66
+ (df_ref.values[:, 2] >= x.values[9]) &
67
+ (df_ref.values[:, 3] <= x.values[10]) &
68
+ (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
69
+
70
+ print(df)
71
+
72
+ ```
73
+
74
+ 以下エラーがでています。
75
+ ---------------------------------------------------------------------------
76
+ IndexError Traceback (most recent call last)
77
+ <ipython-input-3-4a0b1b44785f> in <module>()
78
+ 9 df_ref = pd.read_csv("area_list_test.csv", header=0)
79
+ 10
80
+ ---> 11 df.T.apply(lambda x: ','.join(df_ref[(df_ref.values[:, 1] <= x.values[9]) &
81
+ 12 (df_ref.values[:, 2] >= x.values[9]) &
82
+ 13 (df_ref.values[:, 3] <= x.values[10]) &
83
+
84
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func, axis, broadcast, raw, reduce, result_type, args, **kwds)
85
+ 6012 args=args,
86
+ 6013 kwds=kwds)
87
+ -> 6014 return op.get_result()
88
+ 6015
89
+ 6016 def applymap(self, func):
90
+
91
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
92
+ 316 *self.args, **self.kwds)
93
+ 317
94
+ --> 318 return super(FrameRowApply, self).get_result()
95
+ 319
96
+ 320 def apply_broadcast(self):
97
+
98
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in get_result(self)
99
+ 140 return self.apply_raw()
100
+ 141
101
+ --> 142 return self.apply_standard()
102
+ 143
103
+ 144 def apply_empty_result(self):
104
+
105
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_standard(self)
106
+ 246
107
+ 247 # compute the result using the series generator
108
+ --> 248 self.apply_series_generator()
109
+ 249
110
+ 250 # wrap results
111
+
112
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\apply.py in apply_series_generator(self)
113
+ 275 try:
114
+ 276 for i, v in enumerate(series_gen):
115
+ --> 277 results[i] = self.f(v)
116
+ 278 keys.append(v.name)
117
+ 279 except Exception as e:
118
+
119
+ <ipython-input-3-4a0b1b44785f> in <lambda>(x)
120
+ 12 (df_ref.values[:, 2] >= x.values[9]) &
121
+ 13 (df_ref.values[:, 3] <= x.values[10]) &
122
+ ---> 14 (df_ref.values[:, 4] >= x.values[10])].iloc[:, 21].values.astype(str)))
123
+ 15
124
+ 16 print(df)
125
+
126
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in __getitem__(self, key)
127
+ 1470 except (KeyError, IndexError):
128
+ 1471 pass
129
+ -> 1472 return self._getitem_tuple(key)
130
+ 1473 else:
131
+ 1474 # we by definition only have the 0th axis
132
+
133
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
134
+ 2011 def _getitem_tuple(self, tup):
135
+ 2012
136
+ -> 2013 self._has_valid_tuple(tup)
137
+ 2014 try:
138
+ 2015 return self._getitem_lowerdim(tup)
139
+
140
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
141
+ 220 raise IndexingError('Too many indexers')
142
+ 221 try:
143
+ --> 222 self._validate_key(k, i)
144
+ 223 except ValueError:
145
+ 224 raise ValueError("Location based indexing can only have "
146
+
147
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_key(self, key, axis)
148
+ 1955 return
149
+ 1956 elif is_integer(key):
150
+ -> 1957 self._validate_integer(key, axis)
151
+ 1958 elif isinstance(key, tuple):
152
+ 1959 # a tuple should already have been caught by this point
153
+
154
+ ~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\indexing.py in _validate_integer(self, key, axis)
155
+ 2007 l = len(ax)
156
+ 2008 if key >= l or key < -l:
157
+ -> 2009 raise IndexError("single positional indexer is out-of-bounds")
158
+ 2010
159
+ 2011 def _getitem_tuple(self, tup):
160
+
161
+ IndexError: ('single positional indexer is out-of-bounds', 'occurred at index 0')