Pandas DF Removal of Duplicate Surnames

Panda :

i have DataFrame that has Name of People and Some Names Incorrect Caught surname due to selenium scraping so i want to remove them

Input:

            TEXT    TYPE
0  Barrack Obama  PERSON
1          Obama  PERSON
2      Don Beyer  PERSON
3    Doug Wilson  PERSON
4         Wilson  PERSON
5         Thomas  PERSON

Expected Output

            TEXT    TYPE
0  Barrack Obama  PERSON
1      Don Beyer  PERSON
2    Doug Wilson  PERSON
3         Thomas  PERSON
anky_91 :

Here is another approach using duplicated()

df[~df['TEXT'].str.split().str[-1].duplicated()]

Or:

df[~df['TEXT'].str.split(expand=True).ffill(1).iloc[:,-1].duplicated()]

Or:

df[~df['TEXT'].str.split(expand=True).ffill(1).duplicated([1])]

            TEXT    TYPE
0  Barrack Obama  PERSON
2      Don Beyer  PERSON
3    Doug Wilson  PERSON
5         Thomas  PERSON

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=13829&siteId=1