Script 189: Populate region
In a Nutshell
The script updates the region information for PPC campaigns based on campaign naming conventions.
To Elaborate
- The script is designed to manage and update the regional classification of PPC campaigns.
- It uses campaign names to determine the correct region and applies changes where necessary.
Walking Through the Code
- Constants like
RPT_COL_CAMPAIGN
,RPT_COL_ACCOUNT
, andRPT_COL_REGION
are used to reference specific columns in a dataset. - A temporary field
TMP_FIELD
is created to hold the new region values before they are finalized. - The script searches campaign names for keywords (‘EMEA’, ‘AMER’, ‘APAC’) to assign the corresponding region to
TMP_FIELD
. - It then copies the new region values from
TMP_FIELD
to theoutputDf
DataFrame if there is a change from the original region. - Only campaigns with updated region information are included in the final output, ensuring that no redundant data is processed.
- The script uses
inputDf
as the source data andoutputDf
as the destination for the updated information. - Multiple datasources are not explicitly mentioned, but the script seems to be designed to work with at least two DataFrames: one for input and one for output.
Vitals
- Script ID : 189
- Client ID / Customer ID: 1306920563 / 60268859
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Region
- Created by Jonathan Reichl on 2023-06-14 15:37:13
- Last Updated by Jonathan Reichl on 2023-12-06 04:01:47
> 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_REGION = 'Region'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_REGION = 'Region'
#outputDf[BULK_COL_REGION] = "<<YOUR VALUE>>"
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))
#outputDf[BULK_COL_MARKET] = "<<YOUR VALUE>>"
TMP_FIELD = BULK_COL_REGION + '_new'
# blank out tmp field
inputDf[TMP_FIELD] = numpy.nan
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('EMEA', case=False)) , TMP_FIELD ] = 'EMEA'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('AMER', case=False)) , TMP_FIELD ] = 'AMER'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('APAC', case=False)) , TMP_FIELD ] = 'APAC'
print(tableize(inputDf))
print(inputDf.index.duplicated())
# copy new strategy to output
outputDf.loc[:,BULK_COL_REGION] = inputDf.loc[:, TMP_FIELD]
# only include campaigns with changed strategy in bulk file
outputDf = outputDf[ inputDf[TMP_FIELD].notnull() & (inputDf[RPT_COL_REGION] != inputDf[TMP_FIELD]) ]
Post generated on 2024-02-22 06:05:49 GMT