I have a pandas dataframe that looks like test df
I want to match an "idx" to the very first "Deal No" then remove all repeating deals nos then idxs (repeats of values that are the same as the idx and Deal No, Not all repeats)
As an example for the very first one I match 59 to 465895
then I remove all the other rows in the dataframe where the value in the column "Deal No" is 465895
following that I will remove all the other rows in the dataframe where the value in the column "idx" is 59
for index,row in test.iterrows():#The dataframe I am asking about
cdealno = row['Deal No']
cidx = row['idx']
for index2,row2 in test.iterrows():
if row2['idx'] == cidx:
continue
elif(row2['Deal No'] == cdealno):
test.drop(index2,inplace=True)
for index3,row3 in test.iterrows():
if index3 == index:
continue
elif(row3['idx'] == cidx):
test.drop(index3,inplace=True)
I came up with this code but realized that the values in the first for loop continue to come from the initial state the dataframe was in and not the modified state it would be in after going through a few iterations of the loops within.
The idea is to get a unique 1:1 mapping of idxes to deal nos.
E.g. For idxes 59,60,61 I would like
59 465895
60 465896
61 465897
Idxes 62 and 63 are okay as they already have a 1:1 relationship
For idexs 64 and 65
64 467634
65 467635
For idexs 68 and 69
68 467635
69 467636