Script 151: Campaign Maturity Dimension Tagging

Purpose

The Python script categorizes ExplorAds and Yahoo DSP campaigns into maturity levels based on their spending over the past year.

To Elaborate

The script is designed to assign maturity labels to advertising campaigns based on their spending over the previous 365 days. It specifically targets campaigns from ExplorAds and Yahoo DSP, applying different maturity labels depending on the amount spent. For ExplorAds campaigns, the script assigns labels such as ‘New’, ‘New - Launch’, ‘New - Round 2’, up to ‘New - Round 5’, and ‘Mature’, based on specific spending thresholds. The script aims to provide a structured way to evaluate and categorize campaigns, helping businesses understand the maturity and potential effectiveness of their advertising efforts. The script’s logic has been updated to remove certain thresholds and adjust others, reflecting changes in business rules or strategies.

Walking Through the Code

  1. Define Criteria for ExplorAds Tagging
    • The script sets conditions to determine the maturity level of ExplorAds campaigns based on their spending. It uses logical conditions to check if the spending falls within specific ranges and if the current maturity label is not already set to a particular value.
  2. Create DataFrames for Each Maturity Level
    • For each maturity condition, a new DataFrame is created from the input data, containing only the campaigns that meet the criteria. The maturity label is then assigned to these campaigns.
  3. Merge and Output DataFrames
    • The script combines all non-empty DataFrames into a single output DataFrame. If no campaigns meet the criteria, an empty DataFrame is created. The final output is printed, showing the campaigns and their assigned maturity labels.

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-11-27 06:58:46 GMT

comments powered by Disqus