I am having difficulty creating an IF statement that does the following:
Instead of doing the previous if statement, you can simply look at what has been previously put into the c3
list (as that is a result of the previous if statement).
Here is an example of how you can achieve this in python:
c1 = ["Buy", "nan", "nan", "nan", "Buy", "nan", "nan", "nan", "nan", "Buy", "nan"]
c2 = ["nan", "nan", "Sell", "nan", "nan", "Sell", "Sell", "nan", "nan", "nan", "Sell"]
c3 = []
for index in range(len(c1)):
if c1[index] == "Buy":
c3.append("Buy")
elif c2[index] == "Sell":
c3.append("Sell")
elif c1[index] == "nan" and c2[index] == "nan": # Implied if reached this point (so else would also suffice here)
c3.append(c3[index-1]) # look at previous result in list
print(c3)
Output:
['Buy', 'Buy', 'Sell', 'Sell', 'Buy', 'Sell', 'Sell', 'Sell', 'Sell', 'Buy', 'Sell']