Script 135: Brand Non Brand Dimension Tagging
Purpose
The script tags campaigns as ‘Brand’ or ‘Non-Brand’ based on the presence of the word ‘Brand’ in the campaign name.
To Elaborate
The Python script is designed to categorize marketing campaigns into ‘Brand’ or ‘Non-Brand’ categories. This categorization is based on the presence of the word ‘Brand’ within the campaign name. The script processes a dataset of campaigns, identifies those that include ‘Brand’ in their names, and tags them accordingly. Campaigns without the word ‘Brand’ are tagged as ‘Non-Brand’. This automated tagging helps in organizing and analyzing marketing data, ensuring that campaigns are correctly classified for reporting and strategic decision-making purposes.
Walking Through the Code
-
Initial Setup
The script begins by defining constants for column names used in the input and output dataframes. These constants help in maintaining consistency and readability throughout the script. -
Brand Check
A boolean check (bcheck
) is performed on the campaign names to determine if they contain the word ‘Brand’. This check is case-sensitive and ignores any missing values. - DataFrame Creation
- Two separate dataframes are created based on the
bcheck
result:brandDf
for campaigns identified as ‘Brand’.nonbrandDf
for campaigns identified as ‘Non-Brand’.
- Each dataframe includes columns for account, campaign, and the brand/non-brand tag.
- Two separate dataframes are created based on the
- Tagging
- The
brandDf
dataframe is tagged with ‘Brand’. - The
nonbrandDf
dataframe is tagged with ‘Non-Brand’.
- The
-
Merging DataFrames
The script merges thebrandDf
andnonbrandDf
dataframes into a singleoutputDf
using an outer join, ensuring all campaigns are included in the final output. - Output
The final tagged dataframe is printed in a table format for easy visualization and further analysis.
Vitals
- Script ID : 135
- Client ID / Customer ID: 1306924501 / 60269325
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Brand/Non-Brand
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-05-25 06:29
- Last Updated by lneels@marinsoftware.com on 2023-12-06 04:01
> 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
#
# Bran/Non-Brand Dimension Tagging
#
# Byron Porter
# 2023-05-25
#
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_B_NB = 'Brand/Non-Brand'
# Check if RPT_COL_CAMPAIGN column has 'Brand' in the campaign name
bcheck = (inputDf[RPT_COL_CAMPAIGN].str.contains('Brand', case=True, na=False))
# Use check to create two DataFrames. One for Brand and one for Non-Brand tagging
brandDf = inputDf.loc[bcheck, [BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_B_NB]]
brandDf.loc[:, BULK_COL_B_NB] = 'Brand'
nonbrandDf = inputDf.loc[~bcheck, [BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_B_NB]]
nonbrandDf.loc[:, BULK_COL_B_NB] = 'Non-Brand'
# Merges the Brand and Non-Brand dataframes
outputDf = brandDf.merge(nonbrandDf, how='outer')
# Print the tableized version of the output DataFrame
print(tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT