回答編集履歴
1
エラー情報の追加に対応する回答を追加
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
-
以下
|
9
|
+
以下が確認テストの結果です。
|
10
10
|
|
11
11
|
```python
|
12
12
|
|
@@ -73,3 +73,141 @@
|
|
73
73
|
2018-12-13 12:00:00 128 142 117 134
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
確実ではありませんが、どこかに数字ではないデータが入っている可能性が高いですね。
|
80
|
+
|
81
|
+
以下のデータだとご質問に書かれているのと同じエラーが発生しています。
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```python
|
86
|
+
|
87
|
+
>>> indata = '''Time,Open,High,Low,Close
|
88
|
+
|
89
|
+
... 2018-12-13 10:05,100,150,90,120
|
90
|
+
|
91
|
+
... 2018-12-13 11:07,120,なし,110,130
|
92
|
+
|
93
|
+
... 2018-12-13 11:12,130,145,102,128
|
94
|
+
|
95
|
+
... 2018-12-13 12:18,128,142,117,134'''
|
96
|
+
|
97
|
+
>>>
|
98
|
+
|
99
|
+
>>> with io.StringIO(indata) as f:
|
100
|
+
|
101
|
+
... dataM1 = pd.read_csv(f, engine='python', parse_dates=[0])
|
102
|
+
|
103
|
+
...
|
104
|
+
|
105
|
+
>>> dataM1.set_index('Time', inplace=True)
|
106
|
+
|
107
|
+
>>> def make_mtf_ohlc(dataM1, tf):
|
108
|
+
|
109
|
+
... x = dataM1.resample(tf).ohlc()
|
110
|
+
|
111
|
+
... O = x['Open']['open']
|
112
|
+
|
113
|
+
... H = x['High']['high']
|
114
|
+
|
115
|
+
... L = x['Low']['low']
|
116
|
+
|
117
|
+
... C = x['Close']['close']
|
118
|
+
|
119
|
+
... ret = pd.DataFrame({'Open': O, 'High': H, 'Low': L, 'Close': C},
|
120
|
+
|
121
|
+
... columns=['Open','High','Low','Close'])
|
122
|
+
|
123
|
+
... return ret.dropna()
|
124
|
+
|
125
|
+
...
|
126
|
+
|
127
|
+
>>> ohlc_1h = make_mtf_ohlc(dataM1, '1H')
|
128
|
+
|
129
|
+
Traceback (most recent call last):
|
130
|
+
|
131
|
+
File "<stdin>", line 1, in <module>
|
132
|
+
|
133
|
+
File "<stdin>", line 2, in make_mtf_ohlc
|
134
|
+
|
135
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\resample.py", line 937, in g
|
136
|
+
|
137
|
+
return self._downsample(_method)
|
138
|
+
|
139
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\resample.py", line 1041, in _downsample
|
140
|
+
|
141
|
+
result = obj.groupby(self.grouper, axis=self.axis).aggregate(how, **kwargs)
|
142
|
+
|
143
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 928, in aggregate
|
144
|
+
|
145
|
+
result, how = self._aggregate(func, *args, **kwargs)
|
146
|
+
|
147
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\base.py", line 311, in _aggregate
|
148
|
+
|
149
|
+
return self._try_aggregate_string_function(arg, *args, **kwargs), None
|
150
|
+
|
151
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\base.py", line 267, in _try_aggregate_string_function
|
152
|
+
|
153
|
+
return f(*args, **kwargs)
|
154
|
+
|
155
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 1441, in ohlc
|
156
|
+
|
157
|
+
return self._apply_to_column_groupbys(lambda x: x._cython_agg_general("ohlc"))
|
158
|
+
|
159
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 1759, in _apply_to_column_groupbys
|
160
|
+
|
161
|
+
return concat(
|
162
|
+
|
163
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 271, in concat
|
164
|
+
|
165
|
+
op = _Concatenator(
|
166
|
+
|
167
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 326, in __init__
|
168
|
+
|
169
|
+
objs = list(objs)
|
170
|
+
|
171
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 1760, in <genexpr>
|
172
|
+
|
173
|
+
(func(col_groupby) for _, col_groupby in self._iterate_column_groupbys()),
|
174
|
+
|
175
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 1441, in <lambda>
|
176
|
+
|
177
|
+
return self._apply_to_column_groupbys(lambda x: x._cython_agg_general("ohlc"))
|
178
|
+
|
179
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 908, in _cython_agg_general
|
180
|
+
|
181
|
+
raise DataError("No numeric types to aggregate")
|
182
|
+
|
183
|
+
pandas.core.base.DataError: No numeric types to aggregate
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
データのどの部分に問題があるかを調べるには、以下のようにやってみてください。
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
```python
|
194
|
+
|
195
|
+
>>> print(dataM1['Open'].dtype)
|
196
|
+
|
197
|
+
int64
|
198
|
+
|
199
|
+
>>> print(dataM1['High'].dtype)
|
200
|
+
|
201
|
+
object
|
202
|
+
|
203
|
+
>>> print(dataM1['Low'].dtype)
|
204
|
+
|
205
|
+
int64
|
206
|
+
|
207
|
+
>>> print(dataM1['Close'].dtype)
|
208
|
+
|
209
|
+
int64
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
印字されるのがobjectのところに問題があります。
|