0

I have the following code:

if data['Open'] >= data['Close']:
    data['Color'] = 'True'

What i want to do is compare the two addGreen or Red in [Color] column in pandas. But i am getting

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

How can i fix this?

Slartibartfast
  • 1,058
  • 4
  • 26
  • 60

1 Answers1

2

Try this to see if it works:

import numpy as np
data['Color'] = np.where(data['Open'] >= data['Close'], 'True', 'whatever_value_you_want_if_the_condition_is_false')
Allen Qin
  • 19,507
  • 8
  • 51
  • 67