Script 979: Auto Campaigns tagging Brand vs NonBrand
Purpose
Automatically Tags campaigns with the Brand vs NonBrand Dimension
To Elaborate
The Python script solves the problem of automatically tagging campaigns with the Brand vs NonBrand dimension. It takes an input dataframe that contains campaign data and applies a function to each row to determine whether the campaign is classified as “Brand”, “NonBrand”, or “Unknown”. The script then adds a new column to the output dataframe with the tag for each campaign.
Walking Through the Code
- The script starts by importing the necessary libraries and defining the user changeable parameters.
- The input dataframe is assigned to the variable
inputDf
, which is the primary data source for the script. - The column constants for the campaign, account, and Brand vs NonBrand dimensions are defined.
- The output columns and their initial values are defined.
- The function
tag_brand_vs_nonbrand
is defined, which takes a campaign as input and returns the corresponding tag based on certain conditions. - The function is applied to each row in the input dataframe using the
apply
method, and the results are stored in the output dataframe under the columnBULK_COL_BRAND_VS_NONBRAND
. - The output dataframe is printed to display the tagged campaigns.
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 2024-05-15 07:44:05 GMT