Inputs
I have a Dataframe with several columns. And list
proof_path =
#1 X Y #2 Z #3 W #4
0 p1 a b p2 c p2 a p3
1 p1 a b p2 c p3 a p1
2 p1 a b p2 d p3 e p4
rule = [('#1', 'X', 'Y'), ('#2', 'X', 'Z'), ('#3', 'W', 'Z'), ('#4', 'W', 'Y')]
In the above Dataframe, I want to examine whether each row is duplicated between (#1, X, Y), (#2, X, Z), (#3, W, Z), and (#4, W, Y).
For example In the row corresponding to index 0, (#2, X, Z) and (#3, W, Z) overlap (P2, a, c).
In addition, (#1, X, Y) and (#4, W, Y) in row corresponding to index 1 overlap (P1, a, b).
I'm going to drop rows that overlap between these multi-values from that dataframe.
My desired output is
output
proof_path =
#1 X Y #2 Z #3 W #4
2 p1 a b p2 d p3 e p4
And i tried as follows.
for depth in range(len(rule)-1):
for i in range(1, len(rule)-depth):
current_rComp = proof_path[[rule[depth][0], rule[depth][1], rule[depth][2]]]
current_rComp.columns = ['pred', 'subj', 'obj']
next_rComp = proof_path[[rule[i+depth][0], rule[i+depth][1], rule[i+depth][2]]]
next_rComp.columns = ['pred', 'subj', 'obj']
proof_path = proof_path[current_rComp.ne(next_rComp).any(axis=1)]
Although these methods were able to achieve desired results, they are inefficient by generating new Dataframes for each iteration. Is there a simple way to accomplish these tasks?