Remove duplicates in attribute field

180
2
3 weeks ago
CPoynter
Occasional Contributor III

I have a field with space delimited values eg.:

26199 42448 42448 42454 42483 42497

Tried using pandas etc to explode, strip, split, etc. to list values and recreate as unique values to remove duplicates. Nothing seems to be stringing together to get my desired result:

26199 42448 42454 42483 42497

 I have several thousand rows and need to check for duplicates for all of them, and then update the row values.

Cheers,

Craig

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

code block

 

import numpy as np
def rem_dups(row, sep=' '):
    """Remove duplicates in a string in a row separated by `sep`"""
    s = row.split(sep)
    a = np.array(s)
    u = np.unique(a)
    return " ".join([i for i in u])

row = "26199 42448 42448 42454 42483 42497"

rem_dups(row, sep=' ')
'26199 42448 42454 42483 42497'

expression

rem_dups(!YourFieldName!, sep=' ')

 

 


... sort of retired...
BlakeTerhune
MVP Regular Contributor

Does the order of these values matter after you remove duplicates?

0 Kudos