-
Notifications
You must be signed in to change notification settings - Fork 1
/
mg2Track.py
360 lines (264 loc) · 10.5 KB
/
mg2Track.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# coding: utf-8
# ** Step 1: # Call Pandas and Numpy, set up work directory **
# In[22]:
# Call Pandas and Numpy, set up work directory
import pandas as pd
import numpy as np
get_ipython().magic(u'cd "C:\\Users\\linla\\Documents\\Assignments\\R_SAS_Data"')
# **Step 2: # Read raw data from Local Directory and store it in 'rawdata' **
# In[23]:
rawdata = pd.read_csv("NewOrg_Q3.csv", sep=',', header=False)
julOds = pd.read_csv("julOds.csv", sep=',', header=False)
rawdata1 = pd.merge(rawdata, julOds, how='left', on= 'Worker ID')
rawdata2 = rawdata1.loc[rawdata1['HPEI']=='HPE']
# rawdata.head(5)
# rawdata.columns
len(rawdata2)
# ** ######## Setting variables shortcuts **
# In[24]:
x = rawdata2.copy()
pf = 'Preferred Name'
y = 'Business Lvl 2 (Unit) Desc'
z = 'Management Chain - Level 01 Preferred Name'
zz = 'Management Chain - Level 02 Preferred Name'
b1c = 'Business Lvl 1 (Group) Code'
b2c = 'Business Lvl 2 (Unit) Code'
l1 = 'Business Lvl 1 (Group) Desc'
l3 = 'Business Lvl 3 (Org Chart) Desc'
p_index = ['Management Level']
p_values = ['Primary Compensation Basis - Amount + PTB Rate (USD)', 'Worker ID']
p_columns1 = ['Business Lvl 1 (Group) Code']
p_columns2 = ['Business Lvl 2 (Unit) Code']
mgt_lvl = ['EVP', 'SVP', 'VP', 'SFL', 'DIR', 'FEL', 'STR', 'MG2']
# **Step 2.5 PPS related adjustments**
# In[25]:
hpe_pps_l1 = [
XXX
XXX
]
hpe_pps_dic1 = {
XXX : XXX
XXX : XXX
}# <-- L1 leaders : L1 orgs
# In[26]:
hpe_pps_l2 = [
XXX
XXX
]
hpe_pps_dic2 = {
XXX : XXX
XXX : XXX
}
# In[27]:
for ppsL1 in hpe_pps_l1:
x.loc[(x[l1]=='Printing and Personal System') & (x['FutureL1']==ppsL1), b1c]=hpe_pps_dic1[ppsL1]
x.loc[(x[y].str.startswith('PPS', na=False)) & (x['FutureL1']==ppsL1), b1c]=hpe_pps_dic1[ppsL1]
for ppsL2 in hpe_pps_l2:
x.loc[(x[l1]=='Printing and Personal System') & (x['FutureL2']==ppsL2), b2c]=hpe_pps_dic2[ppsL2]
x.loc[(x[y].str.startswith('PPS', na=False)) & (x['FutureL2']==ppsL2), b2c]=hpe_pps_dic2[ppsL2]
# ** Step 3: # Adjust Foreign Service Expats to align each L1 org based on Management Hierarchy**
# In[28]:
'''
def OFS(x, y, z, b1c):
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Neri, Antonio F'), b1c]='EGR'
return x
t = OFS(rawdata, 'Business Lvl 2 (Unit) Desc', 'Management Chain - Level 01 Preferred Name', 'Business Lvl 1 (Group) Code')
print t
'''
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Ne'), b1c]='EGR'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Fi'), b1c]='LAB'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Go'), b1c]='CMP'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Hi'), b1c]='CCO&TNO'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Ke'), b1c]='HR'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Le'), b1c]='FIN'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Ne'), b1c]='ESHP'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='SF'), b1c]='LEGO'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Yt'), b1c]='SWHP'
x.loc[(x[y]=='Foreign Service Expats') & (x[z]=='Hl'), b1c]='OP_SMO'
# x.loc[x[y]=='Foreign Service Expats']
# x.to_csv('checkpoint3.csv')
# y[(y['Business Lvl 2 (Unit) Desc']=='Foreign Service Expats') & (y['Management Chain - Level 01 Preferred Name']=='Neri Antonio F')]
# ** Step 4: # Adjust Foreign Service Expats to align each L2 org based on Management Hierarchy **
# In[29]:
ofs_lib = [
XXX
XXX
]
ofs_dic = {
XXX : XXX
XXX : XXX
}
for zzz in ofs_lib:
x.loc[(x[y]=='Foreign Service Expats') & (x[zz]==zzz), b2c]=ofs_dic[zzz]
x.loc[(x[y]=='Foreign Service Expats') & (x['Preferred Name']==zzz), b2c]=ofs_dic[zzz]
# x.loc[x[y]=='Foreign Service Expats']
# x.to_csv('checkpoint4.csv')
# ** Step 5: # Align "Seperation" back to their original L2 Orgs **
# In[30]:
sep_dic = {
XXX : XXX
XXX : XXX
}
sep_lib = [
XXX
XXX
]
for zzz in sep_lib:
x.loc[(x[y]=='Separation') & (x[zz]==zzz), b2c]=sep_dic[zzz]
# for those L2 leader themselves:
for zzz in sep_lib:
x.loc[(x[y]=='Separation') & (x['Preferred Name']==zzz), b2c]=sep_dic[zzz]
# x.loc[x[y]=='Separation']
# x.to_csv('checkpoint5.csv')
# ** Step 6: # Align Seperation back to their original L1 Orgs **
# In[31]:
x.loc[(x[y]=='Separation') & (x[z]=='Ne'), b1c]='EGR'
x.loc[(x[y]=='Separation') & (x[z]=='Ve'), b1c]='EGR'
x.loc[(x[y]=='Separation') & (x[z]=='FR'), b1c]='CLU'
x.loc[(x[y]=='Separation') & (x[z]=='Go'), b1c]='CMP'
x.loc[(x[y]=='Separation') & (x[z]=='Hn'), b1c]='TNO'
x.loc[(x[y]=='Separation') & (x[z]=='Ke'), b1c]='HR'
x.loc[(x[y]=='Separation') & (x[z]=='Le'), b1c]='FIN'
x.loc[(x[y]=='Separation') & (x[z]=='Ne'), b1c]='ESHP'
x.loc[(x[y]=='Separation') & (x[z]=='SF'), b1c]='LEGO'
x.loc[(x[y]=='Separation') & (x[z]=='Yt'), b1c]='SWHP'
x.loc[(x[y]=='Separation') & (x[z]=='Hs'), b1c]='OP_SMO'
# tag XX to CSOF/EGR as L1
x.loc[(x[y]=='Separation') & (x[z]=='Mm'), b1c]='CSOF'
x.loc[(x[y]=='Separation') & (x[z]=='Mm'), l3]='Corporate Strategy'
x.loc[(x[y]=='Separation') & (x['Preferred Name']=='Mm'), b1c]='CSOF'
x.loc[(x[y]=='Separation') & (x['Preferred Name']=='Mm'), l3]='Corporate Strategy'
x.loc[(x[y]=='Separation') & (x['Preferred Name']=='ll'), b1c]='EGR'
# x.to_csv('checkpoint6.csv')
# ** Step 7: # Align who report into Hs to CCO&TNO as L1 org **
# **# Adjust the L2 based on the management hierarchy **
# In[32]:
tno_lib = [
XXX
XXX
]
tno_dic = {
# Align those to distinct PHP within CCO&TNO
# Align those to distinct PHP within CCO&TNO
XXX : XXX
XXX : XXX # Align those to distinct PHP within CCO&TNO
}
x.loc[(x[z]=='HJ')|(x['Preferred Name']=='HJ'), b1c]='CCO&TNO'
for zzz in tno_lib:
x.loc[(x[z]=='HJ') & (x[zz]==zzz), b2c]=tno_dic[zzz]
x.loc[(x[z]=='HJ') & (x['Preferred Name']==zzz), b2c]=tno_dic[zzz]
# Customer Advocacy team setting up
x.loc[(x[z]=='Hn') & (x[zz]=='BR'), b1c]='CCO&TNO'
x.loc[(x[zz]=='BR'), b2c]='CIO TBD'
# x.loc[(x['Management Chain - Level 03 Preferred Name']=='RK'), b1c]='CCO&TNO'
x.loc[(x['Management Chain - Level 03 Preferred Name']=='PH'), b2c]='Customer Advocacy'
x.loc[(x['Management Chain - Level 03 Preferred Name']=='GL'), b2c]='Customer Advocacy' # name changed since Jul
ca_lib = [
XXX
XXX
]
for zzz in ca_lib:
x.loc[(x['Preferred Name']==zzz), b1c]='CCO&TNO'
x.loc[(x['Preferred Name']==zzz), b2c]='Customer Advocacy'
# x.to_csv('checkpoint7.csv')
# ** Step 8: # Ch's organization - OP_SMO alignments **
# In[33]:
x.loc[(x[z]=='Hl'), b1c]='OP_SMO' # All people report through Hsu aligned to OP_SMO
x.loc[(x['Preferred Name']=='Hl'), b1c]='OP_SMO' #Ky & Only H themselves to OP_SMO
x.loc[(x['Preferred Name']=='Hl'),b2c]='Others'
# OP_SMO L2 level adjustments:
op_smo_lib = [
XXX
XXX
]
op_smo_dic = {
XXX : XXX
XXX : XXX
}
for zzz in op_smo_lib:
x.loc[(x[zz]==zzz), b2c]=op_smo_dic[zzz]
x.loc[(x['Preferred Name']==zzz), b2c]=op_smo_dic[zzz]
# x.to_csv('checkpoint8.csv')
# ** Step 9: # non-Hinshaw TNO case **
# In[34]:
# build up the lib & dic here ######???:
non_tno_lib_l1 = [
XXX
XXX
] # <-- L1 leaders
non_tno_lib_l2 = [
XXX
XXX
]
non_tno_dic_l1 = {
XXX : XXX
XXX : XXX
}
for zzz in non_tno_lib_l1:
x.loc[(x[z]!='Hinshaw, John') & (x[l1]=='Technology and Operations') & (x[z]==zzz), b1c]=non_tno_dic_l1[zzz]
for zzz in non_tno_lib_l2:
x.loc[(x[z]!='Hinshaw, John') & (x[l1]=='Technology and Operations') & (x[zz]==zzz), b2c]=non_tno_dic_l2[zzz]
# x.to_csv('checkpoint9.csv')
# ** Step 10: # CSO Quality manually adjustments **
# In[35]:
ql_lib = [
XXX
XXX
]
ql_dic_l1 = {
XXX : XXX
XXX : XXX
}
ql_dic_l2 = {
XXX : XXX
XXX : XXX
}
for zzz in ql_lib:
x.loc[(x['Business Lvl 3 (Org Chart) Desc']=='HP Quality Office') & (x['Preferred Name']==zzz), b1c]=ql_dic_l1[zzz]
x.loc[(x['Business Lvl 3 (Org Chart) Desc']=='HP Quality Office') & (x['Preferred Name']==zzz), b2c]=ql_dic_l2[zzz]
x.to_csv('Q3_checkpoint10_hpe.csv')
# ** Step n: # Pivot tables for L1/L2 **
# In[36]:
pl1 = pd.pivot_table(x, index=p_index, values=p_values, columns=p_columns1, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl, :]
pl2 = pd.pivot_table(x, index=p_index, values=p_values, columns=p_columns2, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl, :]
# pl1
# pl2
# ** Step n+1: # Export tables to Local **
# In[37]:
pl1.to_csv('OrgLvl1_Q3_hpe.csv', sep=',')
pl2.to_csv('OrgLvl2_Q3_hpe.csv', sep=',')
# In[38]:
'''
mgt = ['EVP', 'SVP', 'VP', 'SFL', 'DIR', 'FEL', 'STR', 'MG2']
pl1.loc[mgt, : ]
'''
# ** Step n+2: # Administration Summary **
# In[39]:
rd = x.copy()
admin = rd[(rd['Job Family Group']=='Administration') & (rd['Job Family']=='Assistants') & (rd['Job Title'].str.contains('Assistant'))]
hpfs_admin = rd[(rd['Job Family Group']=='Administration') & (rd[b2c]=='HFS')& (rd['Job Family']=='Assistants') & (rd['Job Title'].str.contains('Assistant'))]
pad1_Q3 = pd.pivot_table(admin, index=None, values=p_values, columns=p_columns1, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len})
pad2_hpfs_Q3 = pd.pivot_table(hpfs_admin, index=None, values=p_values, columns=p_columns2, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len})
pad1_Q3.to_csv('admin_lvl1_Q3_hpe.csv', sep=',')
pad2_hpfs_Q3.to_csv('admin_hpfs_Q3_hpe.csv', sep=',')
# ** Step n+3: # CSOF break down summary **
# In[40]:
csof =rd[rd[b1c]=='CSOF']
pcs3_Q3 = pd.pivot_table(csof, index=p_index, values=p_values, columns=l3, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl,:]
pcs3_Q3.to_csv('pcs3_Q3_hpe.csv',sep=',')
# **Step n+4: # CTO/Labs NFV split **
# In[41]:
cto = rd[rd[b1c]=='LAB']
nfv = 'Network Functions Virtualization'
l4 = 'Business Lvl 4 (MRU) Desc'
cto_nfv = cto[cto[l4]==nfv]
non_nfv = cto[cto[l4]!=nfv]
nfv_Q3 = pd.pivot_table(cto_nfv, index=p_index, values=p_values, columns=l4, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl,:]
non_nfv_Q3 = pd.pivot_table(non_nfv, index=p_index, values=p_values, columns=p_columns2, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl,:]
nfv_Q3.to_csv('nfv_Q3_hpe.csv',sep=',')
non_nfv_Q3.to_csv('non_nfv_Q3_hpe.csv',sep=',')
# ** Step n+5: # FIN L3 break-down (Corp Dev, IR & Treasury)**
# In[42]:
corpDev = rd[(rd[b1c]=='FIN') & (rd[b2c]=='CDV') & (rd['Business Lvl 3 (Org Chart) Desc']=='Corp Development')]
corpDev_Q3 = pd.pivot_table(corpDev, index=p_index, values=p_values, columns=l3, aggfunc={'Primary Compensation Basis - Amount + PTB Rate (USD)':np.sum, 'Worker ID':len}).loc[mgt_lvl,:]
corpDev_Q3.to_csv('corpDev_Q3_hpe.csv')