Get Ids With Similar Address In A New Column
I have a dataframe from which i process some columns to get the matching percentage of address of each customer id with address of every other customer id. If some addresses match
Solution 1:
As per your problem, this solution will work, Code is self-explanatory :)
# Getting the DataFrame as the parameter
def pat_match(df):
# Getting the column values of id and address in seprate listid = df['COD_CUST_ID'].values.tolist()
address = df['ADDRESS'].values.tolist()
# Creating a new column with name 'Ids'df['Ids'] = ""
length01=len(id)
for y in range(0,length01):
# The mathched address Id will will be appended in a list for every address
matched_ids = []
# Calculating list of address with match percentage more than 80%
score=process.extractBests(address[y],address,score_cutoff=80)
# Iterating over every address returned by score one by onefor matched_address in score:
# Getting Customer_ID of every Address
get = df['Customer_ID'][df['Address']==matched_address].tolist()[0]
# Appending the Id into a list
matched_ids.append(get)
# Finally Appending the list of matched ID to the column df['Ids'][df['Customer_ID']==id[y]] = str(matched_ids)
main function :
if __name__ == '__main__':
data = pd.read_csv(r"address_details.csv", skiprows=0)
pat_match(data)
Post a Comment for "Get Ids With Similar Address In A New Column"