Skip to content

Instantly share code, notes, and snippets.

@pietrocolombo
Created March 18, 2021 17:23
Show Gist options
  • Save pietrocolombo/2b01922a753cf8b1d17b49342527cf51 to your computer and use it in GitHub Desktop.
Save pietrocolombo/2b01922a753cf8b1d17b49342527cf51 to your computer and use it in GitHub Desktop.
Delete duplicate contacts and contacts with more or less than 13 digits
import pandas as pd
contacts = pd.read_csv("contacts.csv")
contacts.drop_duplicates(subset=['Numero di telefono']) # name of the column that identifies the telephone number
# clears numbers that have more than 13 digits
index_to_drop = contacts[contacts['Numero di telefono'].map(len) != 13].index
contacts.drop(index_to_drop, inplace=True)
# save in a new csv
contacts.to_csv('contacts_new.csv', index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment