Member-only story
Delete duplicate contacts and contacts with more or less than X digits using Python
2 min readApr 13, 2021
If you export the address book in CSV, you can delete duplicate contacts and also those with phone numbers with more or less than X digits.
First you need to export your contacts in CSV format.
For this tutorial we use python.
First you need to read the csv file:
contacts = pd.read_csv("contacts.csv")
To delete the contacts with the duplicate phone number do this command. You have to replace “Numero di telefono” with the name of the phone number column of your CSV file:
contacts.drop_duplicates(subset=['Numero di telefono'])
# name of the column that identifies the telephone number
If you want to delete duplicate contacts based on multiple columns:
contacts.drop_duplicates(subset=['A', 'B'], keep= 'last')
To delete contacts with more or less than X digits because they are invalid contacts.
# clears numbers that have more than 13 digitsindex_to_drop = contacts[contacts['Numero di telefono'].map(len) != 13].indexcontacts.drop(index_to_drop, inplace=True)