Suppose I have a dataframe which has Column 'A' and Column 'B' How do I drop rows where Column 'A' and 'B' are equal , but not in same row. I only wanto to drop rows where column 'B' is equal to column 'A'
For example Column 'B' from Rows 4, 8 & 9 is equal to Rows 2,3&5 Column 'A'. I want to drop Rows 4, 8 & 9
Column A Column B
1 10 62
2 10 72
3 20 75
4 20 10
5 30 35
6 30 45
7 40 55
8 40 20
9 40 30
Drop Rows 4, 8 & 9 since Column B from rows is equal to column A from row 2,3&5
Expected output
Column A Column B
1 10 62
2 10 72
3 20 75
5 30 35
6 30 45
7 40 55
Rows 4, 8 & 9 needs to be deleted
Adding additional details: Column A and B will never be equal in same row. Multiple rows in Column B may have matching values in Column A. To illustrate I have expanded the dataframe Sorry if my originial row numbers are not matching. To summarize the requirement.
Multiple rows will have column B matching with Column A and expectation is to delete all rows where column B is matching with Column A in any row.
To reiterate Column A and Column B will not be equal in same row
30so it will be retained. In contrast, if all rows were dropped at once, then row 5 will be marked and dropped.column Acould be lost. I don't know if this is desired. That would make the problem interesting.df[~(df['Column B'].isin(df['Column A'])]??? I think we were all overthinking this a little bit yesterday? :) ???