Based on the values in the first column, I'm attempting to construct a column with zeros and ones. Write 1 if the value of the upper cell is greater; else, write 0. An example of code might be as follows:
df = pd.Dataframe({'col1': [1, 2, 1, 3, 0]})
df['col2'] = ...python version of excel formula IF(A2>A3, 1, 0)...
Expected output:
I have tried:
while True:
for index, rows in df.iterrows():
df['col1'] = np.where(df['col1'] > df['col1'][index+1], 1, 0)
But this is very slow and gives wrong results.