I am trying to add a new column, category
, by the existing category's id
.
conditions = [
(result['id'] == 1362) or (result['id'] == 7463),
(result['id'] == 543) or (result['id'] == 3424)]
choices = ['A1', 'A2']
result['category'] = np.select(conditions, choices, default='black')
But, I got an error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-289-7cb2bbdaab53> in <module>()
1 conditions = [
----> 2 (result['id'] == 1362) or (result['id'] == 7463),
3 (result['id'] == 543) or (result['id'] == 3424)]
4 choices = ['A1', 'A2']
5 result['category'] = np.select(conditions, choices, default='black')
/anaconda/lib/python3.6/site-packages/pandas/core/generic.py in __nonzero__(self)
951 raise ValueError("The truth value of a {0} is ambiguous. "
952 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
--> 953 .format(self.__class__.__name__))
954
955 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
How can I correct this?