pandas/python: drop duplicates of same strings with different order

is it possible to drop duplicate of rows with the same strings but of different order within the same column?

exampe: dl3_hr_rank.r0 and hr_dl3_rank.r0

code for df before drop:

data = {'item':['dl3_hr_rank.r0','hr_dl3_rank.r0','hr_kl3_rank.r0',
df = pd.DataFrame(data)

code for df after drop:

data = {'item':['dl3_hr_rank.r0','hr_kl3_rank.r0',
df = pd.DataFrame(data)

ps.i’m having trouble inserting tables with the command.. many thanks, regards




Result df: enter image description here

  • Use pandas.Series.str.split to split by ‘_’
  • Use apply(frozenset) to get a hashable set such that I can use duplicated
  • Use pandas.Series.duplicated with keep=’first’ to keep only the first occurrence of duplicate strings