I am coming from the following Excel table:
I want to create a binary indicator indicating cases where the departure airport is not equal the previous arrival airport - basically reconstructing what I did in Excel (Note: "WENN" is equal to "IF" in English). The dataframe is sorted accordingly. What is the best way to do this with python? Is there a way to solve it with pandas?
And lastly, is there a better and more concise technical formulation to ask this question?
Thanks already!
CodePudding user response:
You could use the shift
method as:
bin_indicator = df['arr_ap_shed'].shift(1).eq(df['dep_ap_shed'])
bin_indicator[0] = False # first pos after `shift` is undefined