wkingnet / stock-analysis

使用python进行股票分析和选股
Mozilla Public License 2.0
289 stars 110 forks source link

大佬,帮忙看下这个报错是什么原因呢? #4

Closed GL-Wen closed 2 years ago

GL-Wen commented 2 years ago

策略1执行完毕,已选出 1870 只股票 用时 145.88 秒 开始执行策略2 000001: 0%| | 0/1870 [00:00<?, ?it/s] Traceback (most recent call last): File "C:\Users\gene\Desktop\stock-analysis\xuangu.py", line 213, in stocklist = run_celue2(stocklist, HS300_信号, df_gbbq, df_today) File "C:\Users\gene\Desktop\stock-analysis\xuangu.py", line 111, in run_celue2 celue2 = celue.策略2(df_stock, HS300_信号, start_date=start_date, end_date=end_date).iat[-1] File "C:\Users\gene\Desktop\stock-analysis\celue.py", line 167, in 策略2 TJ06_MA60.iat[i] = MA60.iat[i - v] File "C:\Users\gene\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\core\indexing.py", line 2220, in getitem key = self._convert_key(key) File "C:\Users\gene\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pandas\core\indexing.py", line 2294, in _convert_key raise ValueError("iAt based indexing can only have integer indexers") ValueError: iAt based indexing can only have integer indexers

wkingnet commented 2 years ago

这需要用IDE运行,出错会断下来,然后你看一下TJ06_MA60和MA60的索引是什么数据。

这个错误是:本来应该是整数型索引值,但实际是其他类型的索引,无法做数值计算,所以报错

GL-Wen commented 2 years ago

这需要用IDE运行,出错会断下来,然后你看一下TJ06_MA60和MA60的索引是什么数据。

这个错误是:本来应该是整数型索引值,但实际是其他类型的索引,无法做数值计算,所以报错

image

是的,v是浮点数,我做了转换,但不知道这样数据会不会有问题

wkingnet commented 2 years ago

我有点忘了这句代码是干嘛用的

int是取整。你自己能确信取整后数值的逻辑正确就行。比如2.1和2.9取整后都是2,你要的结果也是2,而不是2.9是要3