Script 979: Auto Campaigns tagging Brand vs NonBrand
Purpose:
Automatically tags marketing campaigns as either Brand or NonBrand based on their names.
To Elaborate
The Python script is designed to categorize marketing campaigns into two distinct groups: Brand and NonBrand. This categorization is based on specific keywords found within the campaign names. The script scans through each campaign name and assigns a tag of ‘Brand’ if it contains keywords like ‘Brand’ or ‘Branded’. Conversely, if the campaign name includes terms such as ‘NonBrand’, ‘Non brand’, ‘Nonbrand’, or ‘Non-brand’, it is tagged as ‘NonBrand’. If none of these keywords are present, the campaign is labeled as ‘Unknown’. This automated tagging process helps in organizing and analyzing campaigns based on their branding focus, facilitating better structured budget allocation and strategic planning.
Walking Through the Code
- Data Preparation:
- The script begins by defining the primary data source, which is a dataframe containing campaign information. Specific columns are identified for processing, including ‘Campaign’, ‘Account’, and ‘Brand vs NonBrand’.
- Tagging Function:
- A function named
tag_brand_vs_nonbrand
is defined to determine the category of each campaign. It checks for the presence of specific keywords in the campaign name to assign the appropriate tag (‘Brand’, ‘NonBrand’, or ‘Unknown’).
- A function named
- Application of Function:
- The tagging function is applied to each row of the input dataframe using the
apply
method. This populates the ‘Brand vs NonBrand’ column in the output dataframe with the determined tags.
- The tagging function is applied to each row of the input dataframe using the
- Output:
- The script concludes by printing the output dataframe, which now includes the newly tagged ‘Brand vs NonBrand’ column for each campaign.
Vitals
- Script ID : 979
- Client ID / Customer ID: 1306927757 / 60270153
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Brand vs NonBrand
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
- Created by dwaidhas@marinsoftware.com on 2024-04-16 14:25
- Last Updated by dwaidhas@marinsoftware.com on 2024-04-16 14:37
> 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
##
## name: Auto Campaigns tagging Brand vs NonBrand
## description:
## Automatically Tags campaigns with the Brand vs NonBrand Dimension
##
## author: Dana Waidhas
## created: 2024-04-16
##
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_BRAND_VS_NONBRAND = 'Brand vs NonBrand'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_BRAND_VS_NONBRAND = 'Brand vs NonBrand'
def tag_brand_vs_nonbrand(campaign):
if 'Brand' in campaign or 'Branded' in campaign:
return 'Brand'
elif any(word in campaign for word in ['NonBrand', 'Non brand', 'Nonbrand', 'Non-brand']):
return 'NonBrand'
else:
return 'Unknown'
# Apply the function to each row in the input dataframe
outputDf[BULK_COL_BRAND_VS_NONBRAND] = inputDf[RPT_COL_CAMPAIGN].apply(tag_brand_vs_nonbrand)
# user code start here
print(outputDf)
Post generated on 2025-03-11 01:25:51 GMT