<p>我对Python还比较陌生,所以请原谅这个可能很琐碎的问题。你知道吗</p>
<p>我试图在我为特定期货合约计算的<code>RSI</code>值发生变化的情况下产生买入和卖出信号。在我的<code>DataFrame</code>中,我创建了一个名为R <code>S</code>I的列,其中包含我正在引用的值,我要做的是根据预定的逻辑检查每个正在进行的值,如果满足该条件,则生成“买入”或“卖出”,然后为生成的每个信号增加一个计数。i、 例如,我设想一个解决方案,使用<code>for</code>循环比较<code>[i]</code>和<code>[i+1]</code>,但我得到一个错误,它显示-</p>
<pre><code>TypeError: cannot do label indexing on class'pandas.indexes.range.RangeIndex with these indexers [25.714285714285722] of class 'numpy.float64'
</code></pre>
<p>这是我的密码</p>
<pre><code>for i in es.RSI:
Buy = 0
Sell = 0
if es.RSI[i] < 30.0 and es.RSI[i+1] >30.0:
es.RSI[i] = "Buy"
Buy = Buy +1
if es.RSI[i] >70.0 and es.RSI[i+1] < 70.0 :
es.RSI[i] = "Sell"
Sell = Sell +1
</code></pre>