Skip to content Skip to sidebar Skip to footer

How Can I Avoid Loop In This Incomplete Vector Solution

I HAVE CLOSED THIS QUESTION AND STARTED A NEW ONE AS I DIDN'T EXPLAIN IT CORECTLY How can I get a vector to hold previous value in the code How can I avoid using a loop in this sit

Solution 1:

You can use the np.where() function:

ndf.assign(Entry=lambda x: np.where(x['NewSignals'] == 0, x['Revals'], x['Entry']))

Output

    Signals Revals  Entry   EntrySignal Profit  ProfitPct            NewSignals
0   1       101     101.0   1.0         0.0     0.0                  1
1   1       102     102.0   1.0         1.0     0.00980392156862745  0
2   1       105     105.0   1.0         4.0     0.0380952380952381   0
3   1       104     104.0   1.0         3.0     0.028846153846153848 0
4   1       105     105.0   1.0         4.0     0.0380952380952381   0
5   0       106     106.0   0.0         0.0     0.0                  0
6   0       107     107.0   0.0         0.0     0.0                  0
7   0       108     108.0   0.0         0.0     0.0                  0
8   0       109     109.0   0.0         0.0     0.0                  0
9   0       109     109.0   0.0         0.0     0.0                  0

Post a Comment for "How Can I Avoid Loop In This Incomplete Vector Solution"