Script 1357: Dimension Update Remarketing

Purpose

Automates the process of populating a remarketing dimension based on specific campaign name values in a dataset.

To Elaborate

The Python script is designed to automate the task of populating a remarketing dimension within a dataset by analyzing campaign names. It processes a dataset to identify campaigns that should be marked for remarketing based on specific keywords or exact matches within the campaign names. The script applies a set of predefined rules to determine whether a campaign should be classified as “Remarketing” or “No,” ensuring that only relevant campaigns are flagged. This automation helps streamline the process of updating marketing dimensions, reducing manual effort and minimizing errors in classification.

Walking Through the Code

  1. Data Preparation:
    • The script begins by accessing a primary data source, which contains columns for ‘Campaign’, ‘Account’, and ‘Remarketing’.
    • It filters the dataset to exclude rows where the ‘Remarketing’ column is already populated, focusing only on entries that need classification.
  2. Remarketing Determination:
    • A function named determine_remarketing is defined to evaluate each campaign name.
    • The function converts campaign names to lowercase to ensure case-insensitive comparison.
    • It checks for specific keywords like “rlsa”, “remarketing”, and “retargeting”, or exact matches with predefined campaign names, to classify them as “Remarketing”.
    • If none of the conditions are met, the campaign is marked as “No”.
  3. Application and Output:
    • The function is applied to each campaign name in the filtered dataset.
    • The results are stored in a new dataframe, which is then printed to display the updated remarketing classifications.

Vitals

  • Script ID : 1357
  • Client ID / Customer ID: 1306913420 / 60268008
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Remarketing
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Kyle Perkins (kyle.perkins@genesys.com)
  • Created by Kyle Perkins on 2024-08-28 21:16
  • Last Updated by Kyle Perkins on 2024-08-28 21:17
> 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
##
## name: Dimension Update - Remarketing
## description:
##  Automates populating remarketing dimension based on campaign name values.
## 
## author: 
## created: 2024-08-28
## 

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_REMARKETING = 'Remarketing'  # Reference to the remarketing column

# Output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_REMARKETING = 'Remarketing'  # Output remarketing column

# Define the function to determine remarketing based on the provided rules
def determine_remarketing(campaign_name):
    campaign_name = campaign_name.lower()  # Convert to lowercase to ignore case
    
    if "rlsa" in campaign_name:
        return "Remarketing"
    elif "remarketing" in campaign_name:
        return "Remarketing"
    elif "retargeting" in campaign_name:
        return "Remarketing"
    elif campaign_name == "apac_en_abmlite_insurance_001".lower():
        return "Remarketing"
    elif campaign_name == "apac-in_lg-en_mofu_indiacloudlaunch_cl-lp".lower():
        return "Remarketing"
    elif campaign_name == "na_na_video_fy24q4_test_003".lower():
        return "Remarketing"
    elif campaign_name == "na_na_videoaction_001".lower():
        return "Remarketing"
    elif campaign_name == "na_na_youtubeavaya_001".lower():
        return "Remarketing"
    else:
        return "No"

# Filter inputDf to skip rows where Remarketing is already populated
filteredDf = inputDf[inputDf[RPT_COL_REMARKETING].isna()].copy()

# Initialize outputDf so that it only includes rows that have been filtered
outputDf = filteredDf

# Apply the function to each row in the filtered dataframe and set result as the output dataframe value
outputDf[BULK_COL_REMARKETING] = filteredDf[RPT_COL_CAMPAIGN].apply(determine_remarketing)

# Printing the result
print(tableize(outputDf.head()))

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus