Alternative way of writing for loop and if in python when working with a dataframe to make it faster
You can shift the columsn and do comparisons. That will make use of vectorization and should be faster.
selection = (plans_to_csv['mode'].shift(-1) == 'walk') & (plans_to_csv['type'].shift(-2)=='car interaction') & (plans_to_csv['person_id'] == plans_to_csv['person_id'].shift(-2))
plans_to_csv['actual_mode_car']= selection.astype(int)
Note that this sets all the entries to 0 that don't match the comparison. If this is not wanted, you can just do plans_to_csv['actual_mode_car'][selection]= 1