Script 1353: Dimension Update Category

Purpose

Automates the categorization of campaigns by analyzing campaign names and assigning appropriate categories based on predefined rules.

To Elaborate

The Python script is designed to automate the process of categorizing marketing campaigns by examining the names of the campaigns and assigning them to specific categories. This is achieved by applying a set of predefined rules that match certain keywords or patterns within the campaign names to corresponding categories. The script processes a dataset of campaigns, filters out those that already have a category assigned, and applies the categorization logic to the remaining campaigns. This ensures that all campaigns are consistently categorized, which can be crucial for reporting, analysis, and strategic decision-making in marketing operations.

Walking Through the Code

  1. Data Preparation
    • The script begins by loading the primary data source into a DataFrame named inputDf.
    • It identifies key columns such as ‘Campaign’, ‘Account’, and ‘Category’ for processing.
  2. Category Determination Function
    • A function determine_category is defined to categorize campaigns based on their names.
    • The function converts campaign names to lowercase and checks for specific keywords or patterns.
    • Depending on the presence of these keywords, it returns a corresponding category.
  3. Filtering and Processing
    • The script filters out campaigns that already have a category assigned, creating a new DataFrame filteredDf.
    • It initializes outputDf with the filtered data, ensuring only uncategorized campaigns are processed.
  4. Applying Categorization
    • The determine_category function is applied to each campaign name in filteredDf.
    • The results are stored in the ‘Category’ column of outputDf.
  5. Output
    • The script prints the first few rows of the categorized data for verification.

Vitals

  • Script ID : 1353
  • Client ID / Customer ID: 1306913420 / 60268008
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Category
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Kyle Perkins (kyle.perkins@genesys.com)
  • Created by Kyle Perkins on 2024-08-28 19:23
  • Last Updated by Kyle Perkins on 2024-08-28 19:51
> 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
##
## name: Dimension Update - Category
## description:
##  Automates populating category 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_CATEGORY = 'Category'  # Reference to the category column

# Output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CATEGORY = 'Category'  # Output category column

# Define the function to determine the category based on the provided rules
def determine_category(campaign_name):
    campaign_name = campaign_name.lower()  # Convert to lowercase to ignore case
    if "dsa" in campaign_name:
        return "DSA"
    elif "bng_non" in campaign_name:
        return "Chat Software"
    elif "ggl_non" in campaign_name:
        return "Chat Software"
    elif "performance-max" in campaign_name or "performance max" in campaign_name:
        return "PMAX"
    elif "rlsa-compet" in campaign_name or "rlsa_compet" in campaign_name:
        return "RLSA Competitors"
    elif "compet" in campaign_name:
        return "Competitors"
    elif "rlsa-brand" in campaign_name or "rlsa_brand" in campaign_name:
        return "RLSA Brand"
    elif "rlsa-nonbrand" in campaign_name or "rlsa_nonbrand" in campaign_name:
        return "RLSA Non-Brand"
    elif "display_brand" in campaign_name:
        return "Display Prospecting"
    elif "brand" in campaign_name:
        return "Brand"
    elif "videoremarketing" in campaign_name or "youtube-remarketing" in campaign_name or "youtuberemarketing" in campaign_name:
        return "YouTube Remarketing"
    elif "youtube-custom" in campaign_name or "youtube-inmarket" in campaign_name:
        return "YouTube Prospecting"
    elif "callmanagement" in campaign_name:
        return "Call Management"
    elif "rlsa" in campaign_name:
        return "RLSA"
    elif "chat" in campaign_name:
        return "Chat Software"
    elif "contact" in campaign_name:
        return "Contact Center"
    elif "dialer" in campaign_name:
        return "Dialers"
    elif "customerservice" in campaign_name:
        return "Customer Service"
    elif "wfm" in campaign_name or "wem" in campaign_name:
        return "WFM"
    elif "ivr" in campaign_name:
        return "IVR"
    elif "remarketing" in campaign_name or "retargeting" in campaign_name:
        return "Display Remarketing"
    elif "display_" in campaign_name:
        return "Display Prospecting"
    elif "callcenter" in campaign_name:
        return "Call Center"
    elif "cx" in campaign_name or "customerexperience" in campaign_name:
        return "CX"
    elif "pointillist" in campaign_name or "journey" in campaign_name:
        return "Pointillist"
    elif "na_pt-remarketing" in campaign_name:
        return "Display Remarketing"
    elif "na_pt" in campaign_name:
        return "Pointillist"
    elif "summit" in campaign_name or "gitex" in campaign_name or "xperience" in campaign_name or "event" in campaign_name:
        return "Event"
    elif "intent" in campaign_name or "inmarket" in campaign_name or "discovery-prospecting" in campaign_name or "affinity" in campaign_name or "gdn" in campaign_name:
        return "Display Prospecting"
    elif "mk_" in campaign_name or "bng_non" in campaign_name:
        return "Chat Software"
    elif "generic" in campaign_name or "feature" in campaign_name or "product" in campaign_name:
        return "Other"
    else:
        return "Other"

# Filter inputDf to skip rows where category is already populated and copy rows to new filteredDf dataframe
filteredDf = inputDf[~inputDf[RPT_COL_CATEGORY].notna()].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_CATEGORY] = filteredDf[RPT_COL_CAMPAIGN].apply(determine_category)

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

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

comments powered by Disqus