Script 1045: Auto Tag Campaigns with Program Manager Dim

Purpose

Auto Tag Campaigns with Program Manager Dim

To Elaborate

This Python script automates the process of tagging campaigns with program manager information based on the school program associated with each campaign.

Walking Through the Code

  1. The script starts by importing the necessary libraries and defining the necessary constants.
  2. The primary data source and column names are defined.
  3. The output columns and initial values are defined.
  4. A mapping of school programs to program managers is defined.
  5. The script iterates through each row in the input data frame.
  6. For each row, it checks the school program and assigns the corresponding program manager to the output data frame.
  7. If the school program is not found in the mapping, it assigns “Unknown” as the program manager.
  8. The script then prints the tableized version of the first few rows of the input data frame.

Vitals

  • Script ID : 1045
  • Client ID / Customer ID: 1306926629 / 60270083
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Program Manager
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-05-02 21:08
  • Last Updated by dwaidhas@marinsoftware.com on 2024-05-02 21:13
> See it in Action

Python Code

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
##
## name: Auto Tag Campaigns with Program Manager Dim
## description:
##  
## 
## author: 
## created: 2024-05-02
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_SCHOOL_PROGRAM = 'School_Program'
RPT_COL_PROGRAM_MANAGER = 'Program Manager'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_PROGRAM_MANAGER = 'Program Manager'
outputDf[BULK_COL_PROGRAM_MANAGER] = "<<YOUR VALUE>>"


# Define mappings of School Programs to Program Managers
program_manager_mapping = {
    'ADEL_MSOCW': 'Stefan',
    'ADEL_MARTE': 'Stefan',
    'ADEL_MHINF': 'Stefan',
    'NEUN_MLAWS': 'Stefan',
    'NEUN_MLEGL': 'Stefan',
    'PURD_CPMGT': 'Stefan',
    'PURD_CLEAN': 'Stefan',
    'TULA_MOMBA': 'Stefan',
    'NEUN_MPADM': 'Jaime',
    'NEUN_MCJUS': 'Jaime',
    'UNFL_MSAPK': 'Jaime',
    'UNFL_MSPMG': 'Jaime',
    'UNFL_MARTE': 'Jaime',
    'UNFL_MMEDU': 'Jaime',
    'UNTK_CPARA': 'Jaime',
    'COLU_MSOCW': 'Regan',
    'COLU_MARTE': 'Regan',
    'COLU_MMEDU': 'Regan',
    'NYUN_MSOCW': 'Regan',
    'PACE_MCYBR': 'Regan',
    'PACE_MSDSC': 'Regan',
    'PACE_MSCSC': 'Regan',
    'SMUN_MPPOL': 'Regan',
    'UCLA_MSDSC': 'Regan',
    'UCLA_MEMGT': 'Regan',
    'UCLA_MHADM': 'Regan',
    'USCA_MHSGI': 'Regan',
    'VAND_MLEGL': 'Regan',
    'VAND_CHMGT': 'Regan',
    'VAND_CBMGT': 'Regan',
    'ALLC_CORPM': 'Jess',
    'BOST_CPARA': 'Jess',
    'CALU_MOMBA': 'Jess',
    'CALU_MPADM': 'Jess',
    'CALU_MITEC': 'Jess',
    'CALU_MSPMG': 'Jess',
    'CALU_MCOUN': 'Jess',
    'CALU_MMGMT': 'Jess',
    'CALU_BPROS': 'Jess',
    'EMRY_MLEGL': 'Jess',
    'JHUN_MGRIS': 'Jess',
    'JHUN_MSUEN': 'Jess',
    'MTSU_MACCT': 'Jess',
    'MTSU_MOMBA': 'Jess',
    'MTSU_MFINC': 'Jess',
    'RUTG_MMECH': 'Jess',
    'RUTG_MSISE': 'Jess',
    'DEPU_MLEGL': 'Connor',
    'LEHI_MEMHC': 'Connor',
    'LEHI_MEDBA': 'Connor',
    'LEHI_MLEAD': 'Connor',
    'PACE_BLBST': 'Connor',
    'PACE_MPADM': 'Connor',
    'PACE_MACDM': 'Connor',
    'PACE_MEDLT': 'Connor',
    'PACE_MOMBA': 'Connor',
    'UCDA_CLEAN': 'Connor',
    'USCA_MGIST': 'Connor',
    'YESH_MLCYB': 'Connor',
    'YESH_MLEMP': 'Connor',
    'USNF_MOMBA': 'Connor',
    'USNF_MACCT': 'Connor',
    'USNF_MMGMT': 'Connor'
}

# Iterate through rows and assign Program Managers
for index, row in inputDf.iterrows():
    school_program = row[RPT_COL_SCHOOL_PROGRAM]
    if school_program in program_manager_mapping:
        outputDf.at[index, BULK_COL_PROGRAM_MANAGER] = program_manager_mapping[school_program]
    else:
        outputDf.at[index, BULK_COL_PROGRAM_MANAGER] = "Unknown"

# user code starts here
print(tableize(inputDf.head()))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus