Script 151: Campaign Maturity Dimension Tagging

Purpose

Assign ‘New’, ‘ New Launch’, ‘New - Round 2’ , ‘New - Round 3’, ‘New - Round 4’, ‘New - Round 5’, or ‘Mature’ labels to campaigns based on their spend over the previous 365 days.

To Elaborate

The Python script assigns maturity labels to campaigns based on their spend over the previous 365 days. The labels include ‘New’, ‘ New Launch’, ‘New - Round 2’ , ‘New - Round 3’, ‘New - Round 4’, ‘New - Round 5’, or ‘Mature’. The script follows specific rules to determine the label for each campaign. The rules are as follows:

  • Campaigns with a spend less than $100 and belonging to the ‘ExplorAds Google’ account are labeled as ‘New’.
  • Campaigns with a spend between $100 and $160 (excluding $160) and belonging to the ‘ExplorAds Google’ account are labeled as ‘New - Launch’.
  • Campaigns with a spend between $160 and $225 (excluding $225) and belonging to the ‘ExplorAds Google’ account are labeled as ‘New - Round 2’.
  • Campaigns with a spend between $225 and $280 (excluding $280) and belonging to the ‘ExplorAds Google’ account are labeled as ‘New - Round 3’.
  • Campaigns with a spend between $280 and $400 (excluding $400) and belonging to the ‘ExplorAds Google’ account are labeled as ‘New - Round 4’.
  • Campaigns with a spend between $400 and $750 (excluding $750) and belonging to the ‘ExplorAds Google’ account are labeled as ‘New - Round 5’.
  • Campaigns with a spend greater than or equal to $750 and belonging to the ‘ExplorAds Google’ account are labeled as ‘Mature’.

Walking Through the Code

  1. The script defines column parameters for the campaign, account, pub cost, and campaign maturity.
  2. The script creates criteria for determining the maturity label for each campaign based on spend and account.
  3. The script creates separate data frames for each maturity label (e.g., ‘New’, ‘New - Launch’, ‘New - Round 2’, etc.) using the defined criteria.
  4. Each data frame is updated to assign the corresponding maturity label to the ‘Campaign Maturity’ column.
  5. The script merges the non-empty data frames into a single output data frame.
  6. If there are non-empty data frames, the script prints the tableized output data frame.
  7. If there are no non-empty data frames, the script prints “Empty outputDf” and creates an empty output data frame with the required columns.

Vitals

  • Script ID : 151
  • Client ID / Customer ID: 1306925431 / 60269477
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Campaign Maturity
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Byron Porter (bporter@marinsoftware.com)
  • Created by Byron Porter on 2023-05-30 18:54
  • Last Updated by alejandro@rainmakeradventures.com on 2024-01-26 18:56
> 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
#
# Campaign Maturity Dimension Tagging
#
#
# Author: Byron Porter
# Date: 2023-05-31
#
# 2023.11.09 - Removed the $125 in spend threshold for New - Launch campaign maturity label. The "New" label will no longer be used. - BP
# 2023.11.20 - Lowered spend thresholds for each campaign maturity label

# define column parameters
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_CAMP_MATURITY = 'Campaign Maturity'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMP_MATURITY = 'Campaign Maturity'




################################# ExplorAds Tagging ################################# 

# Create criteria for what is considered New vs Mature
new = (inputDf[RPT_COL_PUB_COST] < 100) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY].isnull())
new1 = (inputDf[RPT_COL_PUB_COST] >= 100) & (inputDf[RPT_COL_PUB_COST] < 160) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'New - Launch')
new2 = (inputDf[RPT_COL_PUB_COST] >= 160) & (inputDf[RPT_COL_PUB_COST] < 225) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'New - Round 2')
new3 = (inputDf[RPT_COL_PUB_COST] >= 225) & (inputDf[RPT_COL_PUB_COST] < 280) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'New - Round 3')
new4 = (inputDf[RPT_COL_PUB_COST] >= 280) & (inputDf[RPT_COL_PUB_COST] < 400) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'New - Round 4')
new5 = (inputDf[RPT_COL_PUB_COST] >= 400) & (inputDf[RPT_COL_PUB_COST] < 750) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'New - Round 5')
mature = (inputDf[RPT_COL_PUB_COST] >= 750) & (inputDf[RPT_COL_ACCOUNT] == 'ExplorAds Google') & (inputDf[RPT_COL_CAMP_MATURITY] != 'Mature')

# Use criteria to create new DataFrames. One for each maturity label
newDf = inputDf.loc[new, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
newDf.loc[:, RPT_COL_CAMP_MATURITY] = 'New'

new1Df = inputDf.loc[new1, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
new1Df.loc[:, RPT_COL_CAMP_MATURITY] = 'New - Launch'

new2Df = inputDf.loc[new2, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
new2Df.loc[:, RPT_COL_CAMP_MATURITY] = 'New - Round 2'

new3Df = inputDf.loc[new3, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
new3Df.loc[:, RPT_COL_CAMP_MATURITY] = 'New - Round 3'

new4Df = inputDf.loc[new4, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
new4Df.loc[:, RPT_COL_CAMP_MATURITY] = 'New - Round 4'

new5Df = inputDf.loc[new5, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
new5Df.loc[:, RPT_COL_CAMP_MATURITY] = 'New - Round 5'

matureDf = inputDf.loc[mature, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY]].copy()
matureDf.loc[:, RPT_COL_CAMP_MATURITY] = 'Mature' 


# Merges the defined data frames, excluding those that are empty, and prints resulting outputDf
dataframes = [newDf, new1Df, new2Df, new3Df, new4Df, new5Df, matureDf]
non_empty_dataframes = [df for df in dataframes if not df.empty]

if non_empty_dataframes:
    outputDf = pd.concat(non_empty_dataframes)
    print("outputDf", tableize(outputDf))
else:
    print("Empty outputDf")
    outputDf = pd.DataFrame(columns=[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_CAMP_MATURITY])

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus