-
Notifications
You must be signed in to change notification settings - Fork 1
/
companynamevshs.py
81 lines (70 loc) · 1.96 KB
/
companynamevshs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#Find company whether in HupSpot.
#Import packages and data
import difflib
import pandas as pd
import numpy as np
from nameparser import HumanName
import string
from titlecase import titlecase
import re
from difflib import SequenceMatcher
import datetime
today = datetime.date.today()
def inputexcel(excel1,baseexcel,header1,header2):
e1 = pd.read_excel(excel1 ,header = header1, encoding = 'utf-8')
e2 = pd.read_excel(baseexcel ,header = header2, encoding = 'utf-8')
return e1,e2
e1,e2 = inputexcel('companylist.xlsx','hubspot.xlsx',0,0)
l1 = e1['Name']
l1lo = e1['NameLo']
l2 = e2['Name']
l2 = list(l2)
l2ori = e2['Name']
l2id = list(e2['Company ID'])
for i in range(0,len(l2)):
l2[i] = l2[i].replace(" ","")
l2[i] = l2[i].lower()
l1lo = map(str, l1lo)
l1lo = list(l1lo)
l2lo = map(str, l2)
l2lo = list(l2lo)
common = []
for item in l2lo:
comm = difflib.get_close_matches(item,l1lo,1,cutoff=1)
common.append(comm)
newhs = {"ID":l2id, "Name": l2ori, "Match":common}
newhs = pd.DataFrame(newhs)
newlist = []
for i in range(0,len(newhs['Match'])):
item = newhs['Match'][i]
d = len(item)
if d > 0:
newlist.append(i)
inhslist = []
for i in newlist:
inhslist.append(newhs.iloc[i])
inhsdf = pd.DataFrame(inhslist)
inhsdf.to_excel('inhs%s.xlsx'%today, header=True, index=False)
lolist = inhsdf['Match']
lo = []
#The element in column are like "['element']", this part is to get rid of "['']"
for item in lolist:
p1 = re.compile(r'[[](.*)[]]', re.S)
p2 = re.compile(r"['](.*)[']", re.S)
pp = re.findall(p1, str(item))
pp = re.findall(p2, str(item))
lo.append(pp)
lo = pd.DataFrame(lo)
l1lodf = pd.DataFrame(l1lo)
a = lo[0]
b = l1lodf[0]
diff = list(set(b)-set(a))
difin = []
for item in diff:
ind = list(l1lodf[0]).index(item)
difin.append(ind)
difflist = []
for i in difin:
ele = l1.iloc[i]
difflist.append(ele)
pd.DataFrame(difflist).to_excel('notinhs%s.xlsx'%today, header=True, index=False)