I have a pandas dataframe like this..
order_id buyer_id scheduled_order minutes flag
525 232 1 13 Null
862 232 1 14 Null
1361 232 1 15 Null
1373 232 1 13 Null
1580 232 1 14 Null
1729 232 0 11 Null
1817 232 1 18 Null
I want to set a flag depending upon value of scheduled_order.
If first order is scheduled order(scheduled_order =1) flag should set to 0, else it should check if minutes are greater than 12 then flag should be 1 else 2 Then, for next order if previous order is scheduled order then, flag should set to 3. If previous order is live order(scheduled_order =0) and if minutes is less than 12 then flag should set to 2. if minute is greater than 12 then flag should set to 1.
My desired output is
order_id buyer_id scheduled_order minutes flag
525 232 1 13 0
862 232 1 14 3
1361 232 1 15 3
1373 232 1 13 3
1580 232 1 14 3
1729 232 0 11 3
1817 232 1 18 2
Here is my code in python
for i in range(len(df)):
if(df.scheduled_order[i] == '1'):
speed.flag[i] = '0'
else:
if(minutes > 12):
df.flag[i] = '1'
else:
df.flag[i] = '2'
But when i becomes 1 how do I check for previous scheduled_order value?