Script 235: Group Maturity
Purpose
Assigns ‘New’, ‘Mature I, and ‘Mature II’ labels to Yahoo DSP ad groups based on spend thresholds.
To Elaborate
The Python script assigns maturity labels to Yahoo DSP ad groups based on their spend over the previous 7 days. The labels are ‘New’, ‘Mature I’, and ‘Mature II’. The script takes a DataFrame as input and creates new DataFrames for each maturity label. It then merges these DataFrames and outputs the result.
Walking Through the Code
- The script defines column constants for the input and output DataFrames.
- The script gets the current date.
- The script creates a DataFrame containing only Native Path campaigns for tagging.
- The script defines criteria for determining the maturity labels for Yahoo DSP campaigns.
- The script creates new DataFrames for each maturity label based on the criteria.
- The script merges the non-empty DataFrames and prints the resulting output DataFrame.
- If there are no non-empty DataFrames, the script prints an empty 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-05-15 07:44:05 GMT