0

This is the code eoddf is a dataframe

           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]

What is the issue in this code that exactly? at VALUE1 and VALUE2. How to resolve this issue ? Is this because some index problem or the index has non zero so i need to point to numeric value row in the for loop

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()
Marx Babu
  • 750
  • 3
  • 11
  • 34
  • @Bharath-m I disagree about the duplicate. This code is failing on a max() which not at all what is described in the referenced question. The pandas error (truth value of...) is pretty misleading for min/max operation. – mathieu Jun 20 '19 at 08:28

1 Answers1

1

Your ListHigh and ListLow variables contain a scalar and a Series. That might be why max fails, it tries to compare that scalar with that Series.

By the way, in Python, usually variables are not capitalized.

nnnmmm
  • 7,964
  • 4
  • 22
  • 41