I need to subtract each row in a certain column intrades_right
from each row in a certain column in trades_left
to find all occasions where two conditions for these differences are satisfied. The expected result is the column (indicator2
) with 1 if both conditions are satisfied and 0 otherwise. I have a problem with the second condition, where I try to find the minimal difference between trades_left['ms']
and trades_right['ms']
which is greater or equal to 1. I've used Method #2 from here: https://www.geeksforgeeks.org/python-find-smallest-element-greater-than-k/
Code:
for row in trades_left:
trades_left['indicator2'] = np.where(((trades_left['indicator'] - trades_right['indicator']) == -1) & ((trades_left['ms'] - trades_right['ms']) = min((trades_left['ms'] - trades_right['ms']) for (trades_left['ms'] - trades_right['ms']) if (trades_left['ms'] - trades_right['ms']) >= 1), 1, 0)
This gives me:
File "<ipython-input-58-ae2d13f2e547>", line 2
trades_left['indicator2'] = np.where(((trades_left['indicator'] - trades_right['indicator']) == -1) & ((trades_left['ms'] - trades_right['ms']) == min((trades_left['ms'] - trades_right['ms']) for (trades_left['ms'] - trades_right['ms']) if (trades_left['ms'] - trades_right['ms']) >= 1), 1, 0)
^
SyntaxError: invalid syntax
Aucun commentaire:
Enregistrer un commentaire