Python Forum
How do I change this code for searching duplicats in python ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I change this code for searching duplicats in python ?
#1
This is the code that I use for searching duplicates in my excel sheet :

def check_duplicacy(first_col):
    first_col_list = first_col.tolist()
    aux_first_col = []
    for i in range(len(first_col_list)):
        if not(pd.isnull(first_col_list[i])):
            if(first_col_list[i] in aux_first_col):
                print('Duplicate found in row nunmber:'+ str(first_col_list[i]))
                return first_col_list[i]
            else:
                aux_first_col.append(first_col_list[i])
    print("No duplicacy found")
    return ""
The code works fine just when I have long list of duplicates it runs for ever. How can I change that the moment find an error stops from the loop.?

Best regards,
Eidrizi
Reply


Messages In This Thread
How do I change this code for searching duplicats in python ? - by Eidrizi - Mar-17-2021, 01:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Photo (Beginners problem) Does file change during this code? fiqu 3 1,933 Nov-03-2021, 10:23 PM
Last Post: bowlofred
  Differential equations with initial condition in Python (change a working code) Euler2 1 1,863 May-29-2020, 04:06 PM
Last Post: Euler2
  Code Change Help: Infinite Loop Error bindulam 2 2,308 Mar-10-2019, 11:15 PM
Last Post: hshivaraj
  Omit pronoun/common words when searching in Python fabkhush 1 2,581 Feb-19-2019, 09:12 PM
Last Post: nilamo
  simple code: change to home directory Skaperen 5 3,560 Sep-10-2018, 10:29 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020