If you have Pandas installed (Pandas is a Python-compatible database library), you can do this with the following code:
import pandas as pd
Dicionario_BancoDeDados = {'123.456.789-10' : {'CEP': '11.111-000', 'Logradouro': 'Av. Paulista', 'Numero': 99},
'123.456.789-11' : {'CEP': '11.111-001', 'Logradouro': 'Av. Paulista', 'Numero': 99},
'123.456.789-12' : {'CEP': '11.111-002', 'Logradouro': 'Av. Distante', 'Numero': 99}}
BancoDeDados = pd.DataFrame.from_dict(Dicionario_BancoDeDados).T # .T é a operação de transposição
BancoDeDados
You can find people who live in the same residence by executing:
VizinhosDePredio = BancoDeDados[BancoDeDados.duplicated(['Logradouro', 'Numero'], keep=False) == True]
VizinhosDePredio
In order to circumvent doubts in street names, I suggest you do so before searching for neighbors. I show you below such an implementation:
Dicionario_BancoDeDados = {'123.456.789-10' : {'CEP': '11.111-000', 'Logradouro': 'Av. Paulista', 'Numero': 99},
'123.456.789-11' : {'CEP': '11.111-001', 'Logradouro': 'Avenida Paulista', 'Numero': 99},
'123.456.789-12' : {'CEP': '11.111-002', 'Logradouro': 'Av. Distante', 'Numero': 99}}
BancoDeDados = pd.DataFrame.from_dict(Dicionario_BancoDeDados).T
def AbreviarLogradouro(Logradouro):
Logradouro = Logradouro.replace('Avenida', 'Av.')
Logradouro = Logradouro.replace('Rua', 'R.' )
return Logradouro
BancoDeDados['Logradouro'] = BancoDeDados['Logradouro'].map(lambda x: AbreviarLogradouro(x))
BancoDeDados
Is the ZIP code one of the fields in the database? If you do, may I suggest a response using fuzzywuzzy. Another option is: if you can change the database, you can search all occurrences of ["Avenue","Av.",...] and exchange for what you think is best. The same for ["Street","R.",...].
– Rocchi
What are you using? Pure Python? No framework?
– Sidon