1

I have a following code:

def joinOneRow(ser, df):
     temp = df[df.index == 
                max(df.index[df.index <= 
                ser.index[0]])]
     return temp.values[0][0], temp.values[0][1];

def joinWithData(df1, df):
    askTemp, bidTemp = zip(*df1.apply(joinOneRow, args = (df)))

    return askTemp, bidTemp

Index in df1 and df is a Timestamp. df has 2 columns. The problem is when I would like to do the following line:

askTemp, bidTemp = zip(*trades.apply(ef.joinWithData, args = ob))

I have an error:

"The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."

Update for traceback:

Traceback (most recent call last):

File "<ipython-input-5-f74779a26578>", line 1, in <module>
 askTemp, bidTemp = zip(*trades1.apply(ef.joinWithData, args = ob1))

File "C:\Anaconda\lib\site-packages\pandas\core\frame.py", line 6003, in 
 apply
  kwds=kwds)

File "C:\Anaconda\lib\site-packages\pandas\core\apply.py", line 29, in 
frame_apply
  args=args, kwds=kwds)

File "C:\Anaconda\lib\site-packages\pandas\core\apply.py", line 39, in 
 __init__
  self.args = args or ()

   File "C:\Anaconda\lib\site-packages\pandas\core\generic.py", line 1573, 
in __nonzero__
   .format(self.__class__.__name__))

 ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
ltrd
  • 326
  • 1
  • 8
  • 1
    Can you provide **full traceback** for your error? – jpp Oct 23 '18 at 10:51
  • You can get some help from here: https://stackoverflow.com/questions/36921951/truth-value-of-a-series-is-ambiguous-use-a-empty-a-bool-a-item-a-any-o – Bhaskar Oct 23 '18 at 11:37

1 Answers1

0

Try:

askTemp, bidTemp = zip(*trades.apply(ef.joinWithData, args = (ob, ))

referencing: Pass Dataframe to Apply function pandas as argument