Script 235: Group Maturity
Purpose
The script categorizes Yahoo DSP ad groups into ‘New’, ‘Mature I’, and ‘Mature II’ based on their spending over the previous 7 days.
To Elaborate
The Python script is designed to classify Yahoo DSP ad groups into different maturity levels based on their spending over the past week. It specifically targets ad groups within the ‘Native Path’ account. The script applies predefined spending thresholds to determine the maturity level of each ad group: ‘New’ for spending between $500 and $750, ‘Mature I’ for spending between $750 and $1000, and ‘Mature II’ for spending over $1000. The script ensures that ad groups are only upgraded to a higher maturity level if they meet the criteria and have not already been assigned that level. This classification helps in managing and optimizing ad campaigns by identifying which groups are new and which have matured based on their spending patterns.
Walking Through the Code
- Data Preparation
- The script begins by filtering the input data to include only those ad groups that belong to the ‘Native Path’ account. This is done by creating a DataFrame
npathDf
that contains relevant columns for further processing.
- The script begins by filtering the input data to include only those ad groups that belong to the ‘Native Path’ account. This is done by creating a DataFrame
- Defining Maturity Criteria
- It sets up conditions to classify ad groups into ‘New’, ‘Mature I’, and ‘Mature II’ based on their spending (
RPT_COL_PUB_COST
) and current maturity status (RPT_COL_GROUP_MATURITY
). - ‘New’ groups are those with spending between $500 and $750 and no existing maturity label.
- ‘Mature I’ groups have spending between $750 and $1000 and are not already labeled as ‘Mature I’.
- ‘Mature II’ groups have spending over $1000 and are not already labeled as ‘Mature II’.
- It sets up conditions to classify ad groups into ‘New’, ‘Mature I’, and ‘Mature II’ based on their spending (
- Creating Maturity DataFrames
- For each maturity level, the script creates a separate DataFrame (
npnewDf
,npmature1Df
,npmature2Df
) containing ad groups that meet the respective criteria. - It assigns the appropriate maturity label to the
RPT_COL_GROUP_MATURITY
column for each group.
- For each maturity level, the script creates a separate DataFrame (
- Merging and Output
- The script combines the non-empty DataFrames into a single output DataFrame
outputDf
. - If no ad groups meet the criteria, it initializes an empty DataFrame with the necessary columns.
- The final output is printed, showing the maturity classification of the ad groups.
- The script combines the non-empty DataFrames into a single output DataFrame
Vitals
- Script ID : 235
- Client ID / Customer ID: 1306925569 / 60269477
- Action Type: Bulk Upload (Preview)
- Item Changed: AdGroup
- Output Columns: Account, Campaign, Group, Group Maturity
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-07-10 14:29
- Last Updated by Byron Porter 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_GROUP_MATURITY = 'Group Maturity'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_GROUP_MATURITY = 'Group Maturity'
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
################################# Native Path Tagging #################################
# Create Data Frame containing only Native Path campaigns for tagging
npath = inputDf[RPT_COL_ACCOUNT] == 'Native Path'
npathDf = inputDf.loc[npath, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, RPT_COL_GROUP_MATURITY]].copy()
# Create criteria for what is considered New vs Mature for Yahpp DSP campaigns
npnew = (inputDf[RPT_COL_PUB_COST] >= 500) & (inputDf[RPT_COL_PUB_COST] < 750) & (inputDf[RPT_COL_GROUP_MATURITY].isnull())
npmature1 = (inputDf[RPT_COL_PUB_COST] >= 750) & (inputDf[RPT_COL_PUB_COST] < 1000) & (inputDf[RPT_COL_GROUP_MATURITY] != 'Mature I')
npmature2 = (inputDf[RPT_COL_PUB_COST] >= 1000) & (inputDf[RPT_COL_GROUP_MATURITY] != 'Mature II')
# Use criteria to create new DataFrames. One for each maturity label
npnewDf = npathDf.loc[npnew, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, RPT_COL_GROUP_MATURITY]]
npnewDf.loc[:, RPT_COL_GROUP_MATURITY] = 'New'
npmature1Df = npathDf.loc[npmature1, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, RPT_COL_GROUP_MATURITY]]
npmature1Df.loc[:, RPT_COL_GROUP_MATURITY] = 'Mature I'
npmature2Df = npathDf.loc[npmature2, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, RPT_COL_GROUP_MATURITY]]
npmature2Df.loc[:, RPT_COL_GROUP_MATURITY] = 'Mature II'
# Merges the defined data frames, excluding those that are empty, and prints resulting outputDf
dataframes = [npnewDf, npmature1Df, npmature2Df]
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_GROUP, RPT_COL_GROUP_MATURITY])
Post generated on 2024-11-27 06:58:46 GMT