If/else 在 pandas 值错误

If/else in pandas ValueError

我有以下代码:

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

我想做的是比较pandas中[Color]列中的两个addGreenRed。但是我得到

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

我该如何解决这个问题?

试试看是否有效:

import numpy as np
data['Color'] = np.where(data['Open'] >= data['Close'], 'True', 'whatever_value_you_want_if_the_condition_is_false')