回答編集履歴
1
エラー情報の追加に対応する回答を追加
answer
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
従って、データが間違っているか、その加工に誤りがあるのでしょう。
|
3
3
|
エラーコード全文を載せていただければ、もう少しわかるかもしれません。
|
4
4
|
|
5
|
-
以下
|
5
|
+
以下が確認テストの結果です。
|
6
6
|
```python
|
7
7
|
>>> import pandas as pd
|
8
8
|
>>> import io
|
@@ -35,4 +35,73 @@
|
|
35
35
|
2018-12-13 10:00:00 100 150 90 120
|
36
36
|
2018-12-13 11:00:00 120 160 102 128
|
37
37
|
2018-12-13 12:00:00 128 142 117 134
|
38
|
-
```
|
38
|
+
```
|
39
|
+
|
40
|
+
確実ではありませんが、どこかに数字ではないデータが入っている可能性が高いですね。
|
41
|
+
以下のデータだとご質問に書かれているのと同じエラーが発生しています。
|
42
|
+
|
43
|
+
```python
|
44
|
+
>>> indata = '''Time,Open,High,Low,Close
|
45
|
+
... 2018-12-13 10:05,100,150,90,120
|
46
|
+
... 2018-12-13 11:07,120,なし,110,130
|
47
|
+
... 2018-12-13 11:12,130,145,102,128
|
48
|
+
... 2018-12-13 12:18,128,142,117,134'''
|
49
|
+
>>>
|
50
|
+
>>> with io.StringIO(indata) as f:
|
51
|
+
... dataM1 = pd.read_csv(f, engine='python', parse_dates=[0])
|
52
|
+
...
|
53
|
+
>>> dataM1.set_index('Time', inplace=True)
|
54
|
+
>>> def make_mtf_ohlc(dataM1, tf):
|
55
|
+
... x = dataM1.resample(tf).ohlc()
|
56
|
+
... O = x['Open']['open']
|
57
|
+
... H = x['High']['high']
|
58
|
+
... L = x['Low']['low']
|
59
|
+
... C = x['Close']['close']
|
60
|
+
... ret = pd.DataFrame({'Open': O, 'High': H, 'Low': L, 'Close': C},
|
61
|
+
... columns=['Open','High','Low','Close'])
|
62
|
+
... return ret.dropna()
|
63
|
+
...
|
64
|
+
>>> ohlc_1h = make_mtf_ohlc(dataM1, '1H')
|
65
|
+
Traceback (most recent call last):
|
66
|
+
File "<stdin>", line 1, in <module>
|
67
|
+
File "<stdin>", line 2, in make_mtf_ohlc
|
68
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\resample.py", line 937, in g
|
69
|
+
return self._downsample(_method)
|
70
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\resample.py", line 1041, in _downsample
|
71
|
+
result = obj.groupby(self.grouper, axis=self.axis).aggregate(how, **kwargs)
|
72
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 928, in aggregate
|
73
|
+
result, how = self._aggregate(func, *args, **kwargs)
|
74
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\base.py", line 311, in _aggregate
|
75
|
+
return self._try_aggregate_string_function(arg, *args, **kwargs), None
|
76
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\base.py", line 267, in _try_aggregate_string_function
|
77
|
+
return f(*args, **kwargs)
|
78
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 1441, in ohlc
|
79
|
+
return self._apply_to_column_groupbys(lambda x: x._cython_agg_general("ohlc"))
|
80
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 1759, in _apply_to_column_groupbys
|
81
|
+
return concat(
|
82
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 271, in concat
|
83
|
+
op = _Concatenator(
|
84
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\reshape\concat.py", line 326, in __init__
|
85
|
+
objs = list(objs)
|
86
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\generic.py", line 1760, in <genexpr>
|
87
|
+
(func(col_groupby) for _, col_groupby in self._iterate_column_groupbys()),
|
88
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 1441, in <lambda>
|
89
|
+
return self._apply_to_column_groupbys(lambda x: x._cython_agg_general("ohlc"))
|
90
|
+
File "C:\Users\myname\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 908, in _cython_agg_general
|
91
|
+
raise DataError("No numeric types to aggregate")
|
92
|
+
pandas.core.base.DataError: No numeric types to aggregate
|
93
|
+
```
|
94
|
+
|
95
|
+
データのどの部分に問題があるかを調べるには、以下のようにやってみてください。
|
96
|
+
|
97
|
+
```python
|
98
|
+
>>> print(dataM1['Open'].dtype)
|
99
|
+
int64
|
100
|
+
>>> print(dataM1['High'].dtype)
|
101
|
+
object
|
102
|
+
>>> print(dataM1['Low'].dtype)
|
103
|
+
int64
|
104
|
+
>>> print(dataM1['Close'].dtype)
|
105
|
+
int64
|
106
|
+
```
|
107
|
+
印字されるのがobjectのところに問題があります。
|