这是代码eoddf是一个数据帧
Symbol Series Prev Close Open High Low Last Close \
Date
2015-01-01 SBIN EQ 311.85 312.45 315.00 310.70 314.00 314.00
2015-01-02 SBIN EQ 314.00 314.35 318.30 314.35 315.60 315.25
2015-01-05 SBIN EQ 315.25 316.25 316.80 312.10 312.80 312.75
2015-01-06 SBIN EQ 312.75 310.00 311.10 298.70 299.90 299.90
2015-01-07 SBIN EQ 299.90 300.00 302.55 295.15 301.40 300.15
2015-01-08 SBIN EQ 300.15 305.00 306.50 302.35 305.25 304.85
2015-01-09 SBIN EQ 304.85 306.70 307.85 302.00 303.00 303.20
2015-01-12 SBIN EQ 303.20 304.15 307.80 301.10 306.90 307.10
2015-01-13 SBIN EQ 307.10 308.15 310.75 304.15 305.25 305.10
2015-01-14 SBIN EQ 305.10 304.00 307.00 302.25 305.00 304.70
2015-01-15 SBIN EQ 304.70 319.90 323.70 314.00 318.40 320.30
FirstHighValue =eoddf['High']
FirstLowValue =eoddf['Low']
Swing =1
OLDSwing=Swing
for Open in range(1, len(eoddf)):
OLDSwing=Swing
ListHigh =[eoddf['High'][Open],FirstHighValue]
ListLow =[eoddf['Low'][Open],FirstLowValue]
VALUE1 = max(ListHigh)
VALUE2 = min(ListLow)
if (OLDSwing==1 and eoddf['Low'][Open]<VALUE2): Swing=-1;
if (OLDSwing==-1 and eoddf['High'][Open]>VALUE1 ): Swing=1;
if (Swing==1):
HighBuffer[Open]=eoddf['High'][Open]; LowBuffer[Open]=eoddf['Open'][Open]
if (Swing==-1):
LowBuffer[Open]=eoddf['High'][Open]; HighBuffer[Open]=eoddf['Low'][Open]
这段代码究竟是什么问题?在VALUE1和VALUE2。 如何解决这个问题? 这是因为某些索引问题或索引非零,所以我需要指向for循环中的数值行
Traceback (most recent call last):
line 420, in <module>
VALUE1 = max(ListHigh)
line 953, in __nonzero__
.format(self.__class__.__name__))
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
答案 0 :(得分:1)
您的ListHigh
和ListLow
变量包含标量和系列。这可能是max
失败的原因,它试图将该标量与该系列进行比较。
顺便说一下,在Python中,通常变量不是大写的。