I have a pandas dataframe which looks like below (rows are always unique)
Start End Status AB DD T_DOWN TR WE T_UP DD RE P_DOWN TR WE R_WAITYT GG R_WAIT GG LO P_DOWN
What I want to do is to find out rows where Start value of one row equals End value of another row and Status value of such rows either contains the string T_DOWN
or P_DOWN
. So if such condition exists, then keep the row which contains Status value P_DOWN
So in the example above, the third row's Start value is DD
which matches with first row's End value which is also DD
and both the rows have presence of T_DOWN
and P_DOWN
. So I would keep the third row since it contains the Status value P_DOWN
As a counter example, notice the sixth row whose Start value is GG
and the fifth row's End value is also GG
. But the rows contain Status values have R_WAIT
and P_DOWN
. So these rows will not be considered.
So final result would look like
Start End Status TR WE T_UP DD RE P_DOWN TR WE R_WAITYT GG R_WAIT GG LO P_DOWN
But I just can't figure out how to do this comparison.I looked up some resources online where the comparison logic appears a little bit similar to what I am trying to do but yet not close enough to give me a head start.
Compare Multiple Columns to Get Rows that are Different in Two Pandas Dataframes
Pandas dataframe compare multiple rows with specific condition
Can anybody help me with this?