Reputation: 595
I know this error message has been discussed on here before but I still cannot figure out how to make this work. I'm trying to do a np.where statement with more than one condition. Below is my code. I am getting the error message "Keyword can't be an expression" and it is highlighting the space after "aggregate['Counter'] > 1.
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) = aggregate['3']), 0, aggregate['2'])
Upvotes: 3
Views: 4800
Reputation: 1521
You need a double equals sign:
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) == aggregate['3']), 0, aggregate['2']
Upvotes: 3
Reputation: 500773
The comparison operator is ==
, not =
:
...aggregate['2'].shift(1) == aggregate['3']),...
^^ here
Upvotes: 7