-1

There are my code and dataframe: dataframe

I am trying to receive signal from the dataframe and return 1,-1,0. For example: If the dataframe show that the latest signal columns is 1, then return 1

Then a problem popped up ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

def signal_copyer(signal):
  if signal>0:
    return 1 

  if signal<0:
     return -1

  else:
     return 0 
Czz
  • 1
  • 3
  • 1
    please provide a [**minimal reproducible input**](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and the explicit matching expected output. – mozway Jan 21 '23 at 10:17

1 Answers1

0

I assume that signal is pd.Series object and you want to use the last value in Series as your signal. In this case I would suggest this

def signal_copyer(signal):
  if signal.iloc[-1] > 0:
    return 1 
  elif signal.iloc[-1] < 0:
     return -1
  else:
     return 0

.iloc[-1] takes last value of your Series

Artyom Akselrod
  • 946
  • 6
  • 14