0

Hi I try to create new column "state" based on this function:

def state (row):
if (np.sign(row) == np.sign(row).shift(1)) and (row > 1):
    return 1
elif (np.sign(row) == np.sign(row).shift(1)) and (row < -1):
    return -1
elif (np.sign (row) == np.sign(row).shift(1)) :
    return (row).shift(1)
else:
    return 0

After applying the function on dataset by this code:

data['state'] = data['zscore'].apply(state)

I got the error: 'numpy.float64' object has no attribute 'shift'.

Any suggestion will be greatly appreciated,

Jana Stará
  • 43
  • 1
  • 1
  • 5
  • Where is `shift` supposed to come from? It does not seem to be a numpy function. Numpy does have `numpy.left_shift` and `numpy.right_shift` though. – jkr Oct 12 '20 at 15:02
  • I see, thank you. Is there any possibility how to compare in function values in row (x) and row (x-1) while using floats? – Jana Stará Oct 12 '20 at 15:09
  • Can you please provide a minimal, reproducible example? Include your dataframe please. This answer might also help https://stackoverflow.com/a/41399555/5666087 – jkr Oct 12 '20 at 15:23

0 Answers0