Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

droping Duplicates

# this is based on 2 factors the name of the dog and the breed of the dog so we can
# have 2 dog with the same name but diff breed.

df.drop_duplicates(subset=["name", "breed"])

# Without including index
df.drop_duplicates(subset=["name", "breed"], index = False)
Comment

Duplicate Remove

from pathlib import Path
import hashlib
import os

def remove_duplicate(path):
    unique = {}
    for file in Path(path).rglob('*'):
        if file.is_file():
            with open(file, 'rb') as f:
                filehash = hashlib.md5(f.read()).hexdigest()
                if filehash not in unique:
                    unique[filehash] = file
                else:
                    # Test print before removing
                    print(f'Removing --> {unique[filehash]}')
                    #os.remove(unique[filehash])

if __name__ == '__main__':
    path = r'C:foo'
    remove_duplicate(path)
Comment

PREVIOUS NEXT
Code Example
Python :: add all elements of list to set python 
Python :: gil python 
Python :: what is print in python 
Python :: or operator in python 
Python :: WARNING: Ignoring invalid distribution c program files python39libsite-packages 
Python :: Routes In Django 
Python :: python string to uppercase 
Python :: print all objects in list python 
Python :: pyhton serialize object 
Python :: function composition python 
Python :: how to remove some indexes from a dataframe in python 
Python :: python string does not contain 
Python :: python list extend 
Python :: NaN stand for python 
Python :: append to a tuple 
Python :: get min of list python 
Python :: linear search in c++ 
Python :: python read array line by line 
Python :: python exit if statement 
Python :: nested dictionary python 
Python :: python syntaxerror: unexpected character after line continuation character 
Python :: del(list) python 
Python :: range(n,n) python 
Python :: Python - How To Convert String to ASCII Value 
Python :: Class 10: Conditional Statements in Python [IF, ELIF, ELSE] 
Python :: Print only small Latin letters a found in the given string. 
Python :: def multiply(a b) a * b 
Python :: python glob sort numerically 
Python :: pandascheck if two columns match and populate new column 
Python :: python multiply numbers nested list 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =