I have a dataframe like this:
source target weight
1 2 5
2 1 5
1 2 5
1 2 7
3 1 6
1 1 6
1 3 6
My goal is to remove the duplicate rows, but the order of source and target columns are not important. In fact, the order of two columns are not important and they should be removed. In this case, the expected result would be
source target weight
1 2 5
1 2 7
3 1 6
1 1 6
Is there any way to this without loops?
Should be fairly easy.
You can drop the duplicates using
drop_duplicates
would result in:
because you want to handle the unordered source/target issue.
and then you can use
df.drop_duplicates()
Use
frozenset
andduplicated
If you want to account for unordered
source
/target
andweight
However, to be explicit with more readable code.