-
Notifications
You must be signed in to change notification settings - Fork 0
/
HSComtoSFAcc.py
225 lines (184 loc) · 9.45 KB
/
HSComtoSFAcc.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Import Salesforce Account from HubSpot Company.
# Data Clean and massage.
import pandas as pd
import re
df = pd.read_csv('all-companies-3-26-3.csv',encoding='utf-8-sig')#,encoding='utf8')
pd.DataFrame(df)
fnc = pd.read_excel('ComAccFieldNameChange.xlsx',encoding='utf8')
fnc = pd.DataFrame(fnc)
savecol = list(fnc['HS Field'])
df_dropped = df[savecol]
for i in range(0,len(fnc)):
n1 = str(fnc['HS Field'][i])
n2 = str(fnc['SF Field'][i])
df_dropped = df_dropped.rename(columns={n1: n2})
df_dropped["Account Protected Status"].replace({"No":"Open",
"Yes - Top 35 Prospect Account":"Protected - Top Prospect"},
inplace=True)
df_dropped["Has Business in APAC"].replace({"Maybe":"",
"Unknown":""},inplace=True)
df_dropped["Has Business in China"].replace({"Maybe":"",
"Unknown":""},inplace=True)
df_dropped["Has Business in LATAM"].replace({"Maybe":"",
"Unknown":""},inplace=True)
df_dropped["Number of Sites in APAC"].replace({"Unknown":""},inplace=True)
df_dropped["Number of Sites in China"].replace({"Unkown":""},inplace=True)
LATAMloca = list(df_dropped["LATAM Site Locations (by Country)"])
for i in range(0,len(LATAMloca)):
if (type(LATAMloca[i])!=float):
LATAMloca[i] = LATAMloca[i].replace("None;","")
LATAMloca[i] = LATAMloca[i].replace("Unknown;","")
LATAMloca[i] = LATAMloca[i].replace("Yes - Unspecified;","")
LATAMloca[i] = LATAMloca[i].replace(";None","")
LATAMloca[i] = LATAMloca[i].replace(";Unknown","")
LATAMloca[i] = LATAMloca[i].replace(";Yes - Unspecified","")
LATAMloca[i] = LATAMloca[i].replace("None","")
LATAMloca[i] = LATAMloca[i].replace("Unknown","")
LATAMloca[i] = LATAMloca[i].replace("Yes - Unspecified","")
df_dropped["LATAM Site Locations (by Country)"] = LATAMloca
AsLiTag = list(df_dropped["Association/List Tag"])
for i in range(0,len(AsLiTag)):
if (type(AsLiTag[i])!=float):
AsLiTag[i] = AsLiTag[i].replace("Nickname Update w/o Cleaning;","")
AsLiTag[i] = AsLiTag[i].replace(";Nickname Update w/o Cleaning","")
AsLiTag[i] = AsLiTag[i].replace("Nickname Update w/o Cleaning","")
AsLiTag[i] = AsLiTag[i].replace("Nickname Update;","")
AsLiTag[i] = AsLiTag[i].replace(";Nickname Update","")
AsLiTag[i] = AsLiTag[i].replace("Nickname Update","")
AsLiTag[i] = AsLiTag[i].replace("Potential Banned Company;","")
AsLiTag[i] = AsLiTag[i].replace(";Potential Banned Company","")
AsLiTag[i] = AsLiTag[i].replace("Potential Banned Company","")
AsLiTag[i] = AsLiTag[i].replace("Uniworld All Data;","")
AsLiTag[i] = AsLiTag[i].replace(";Uniworld All Data","")
AsLiTag[i] = AsLiTag[i].replace("Uniworld All Data","")
df_dropped["Association/List Tag"] = AsLiTag
AccProSta = list(df_dropped["Account Protected Status"])
Lifecycle = list(df_dropped["Lifecycle Stage"])
Typelist = list(df_dropped["Type"])
for i in range(0,len(df_dropped)):
if (AccProSta[i] == "Yes - Opportunity Account"):
if (Typelist[i] == "Channel Partner") or (Lifecycle[i] == "Evangelist"):
AccProSta[i] = "Protected - Active Opportunity Agent"
else:
AccProSta[i] = "Protected - Active Opportunity Account"
for i in range(0,len(df_dropped)):
if (AccProSta[i] == "Yes - Customer Account"):
if (Typelist[i] == "Channel Partner") or (Lifecycle[i] == "Evangelist"):
AccProSta[i] = "Protected - Billing Agent"
else:
AccProSta[i] = "Protected - Billing Customer"
df_dropped["Account Protected Status"] = AccProSta
ComStatus = list(df_dropped["Company Status (Data Backup - HubSpot)"])
for i in range(0,len(df_dropped)):
if (ComStatus[i] == "Action Needed") or (ComStatus[i] == "Prospecting") or (ComStatus[i] == "Pre-Qualify"):
if (Lifecycle[i] == "Subscriber"):
Lifecycle[i] = "Lead"
elif (Lifecycle[i] == "Marketing Qualified Lead"):
Lifecycle[i] = "Marketing Qualified Lead"
elif (Lifecycle[i] == "Sales Qualified Lead"):
Lifecycle[i] = "Sales Qualified Lead"
for i in range(0,len(df_dropped)):
if (Lifecycle[i] == "Opportunity"):
if (ComStatus[i] == "Active Opportunity"):
Lifecycle[i] = "Active Opportunity"
elif (ComStatus[i] == "Lost Opportunity"):
Lifecycle[i] = "Lost Opportunity"
for i in range(0,len(df_dropped)):
if (Lifecycle[i] == "Customer"):
if (ComStatus[i] == "Billing Customer"):
Lifecycle[i] = "Billing Customer"
elif (ComStatus[i] == "Lost Customer"):
Lifecycle[i] = "Lost Customer"
df_dropped["Lifecycle Stage"] = Lifecycle
df_dropped["Lifecycle Stage"].replace({"Evangelist":"Billing Customer",
"Other":"Disqualified"},inplace=True)
AccSource = list(df_dropped["Account Source"])
MarProBre = list(df_dropped["Marketing Prospecting Breakdown"])
for i in range(0,len(df_dropped)):
if (AccSource[i] == "Marketing Prospecting"):
if (MarProBre[i] == "Online Prospecting"):
AccSource[i] = "Online Research"
elif (MarProBre[i] == "Web Traffic"):
AccSource[i] = "Web - Direct Traffic"
elif (MarProBre[i] == "Weekly Intelligence Research"):
AccSource[i] = "Online Research"
elif (MarProBre[i] == "Outreach"):
AccSource[i] = "Online Research"
elif (MarProBre[i] == "Campaign"):
AccSource[i] = "Email Campaign"
else:
AccSource[i] = "Online Research"
df_dropped["Account Source"] = AccSource
df_dropped["Account Source"].replace({"Sales Discovery":"Online Research",
"Channel Partner/Agent":"Channel Sub Agent"},inplace=True)
ChanParType = list(df_dropped["Channel Partner Type"])
for i in range(0,len(df_dropped)):
if (Typelist[i] == "Channel Partner") and (ChanParType[i] == "Channel Master Agent"):
Typelist[i] = "Channel Master Agent"
elif (Typelist[i] == "Channel Partner") and (ChanParType[i] != "Channel Master Agent"):
Typelist[i] = "Channel Sub Agent"
elif (Typelist[i] != "Channel Master Agent") and (Typelist[i] != "Channel Sub Agent"):
Typelist[i] = "Direct Customer Account"
df_dropped["Type"] = Typelist
df_dropped["Disqualify Reasons"].replace({"No China/APC Business":"Irrelevant",
"No Longer Exist":"No Longer Existed",
"Invalid Input":"Invalid Entry",
"Other Reason":"Other Resons (To Be Specified)",
"Not Interested in CTA":"Irrelevant"},
inplace=True)
df_new = df_dropped.drop(columns=["Channel Partner Type", "Marketing Prospecting Breakdown"])
user = pd.read_excel('User-updated.xlsx',encoding='utf-8-sig')
user = pd.DataFrame(user)
userid = user['Id']
username = user['HS User']
dfuser = df_new['Account Owner']
for i in range(0,len(user)):
n1 = userid[i]
n2 = username[i]
df_new["Account Owner"].replace({n2:n1},inplace=True)
samplelist = df_new['China Site Locations (by Province)']
fulllist = []
for i in range(0,len(samplelist)):
if type(samplelist[i])!=float:
word = samplelist[i].split("; ")
fulllist = fulllist + word
finalcity = list(set(fulllist))
pd.DataFrame(finalcity).to_excel("allcity-in-HS.xlsx")
glob = pd.read_excel('ComAccGlobal.xlsx',encoding='utf-8-sig')
glob = pd.DataFrame(glob)
globold = glob['0 - Global Headquarter']
globnew1 = glob['Americas Headquarter']
globnew2 = glob['Global Headquarter']
localist = list(df_new["Global Headquarter"])
df_new["Americas Headquarter"] = df_new["Global Headquarter"]
for i in range(0,len(glob)):
n1 = globold[i]
n2 = globnew1[i]
n3 = globnew2[i]
df_new["Global Headquarter"].replace({n1:n3},inplace=True)
df_new["Americas Headquarter"].replace({n1:n2},inplace=True)
headq = pd.read_excel('ComAccChinaProvince.xlsx',encoding='utf-8-sig')
headq = pd.DataFrame(headq)
headold = headq['1 - China Site Locations']
headnew = headq['China Site Locations (by Province)']
headfile = list(df_new['China Site Locations (by Province)'])
head_dict = dict(zip(headold, headnew))
for i in range(0,len(df_new)):
if type(headfile[i])!=float:
wordstr = headfile[i].split("; ")
for key in head_dict:
for j in range(0,len(wordstr)):
if (len(key)==len(wordstr[j])):
wordstr[j] = wordstr[j].replace(key, head_dict[key])
rep = list(set(wordstr))
listToStr = ';'.join([str(elem) for elem in rep])
headfile[i] = listToStr
for i in range(0,len(headfile)):
if (type(headfile[i])!=float):
headfile[i] = headfile[i].replace("Wrong Value;","")
headfile[i] = headfile[i].replace(";Wrong Value","")
headfile[i] = headfile[i].replace("Wrong Value","")
df_new['China Site Locations (by Province)'] = headfile
df_provice = df_new[['China Site Locations (by Province)','HubSpot Company ID (HS Integration)']]
pd.DataFrame(df_provice).to_excel("provice-update-to-HS.xlsx")
df_new.to_csv('accfinish-final-version.csv', index=False, encoding='utf-8-sig')