Script 587: ABO Budget Assignment
Purpose
The script assigns corrected budget values at the campaign level and labels campaigns using ABO Budgets.
To Elaborate
The Python script is designed to process advertising data, specifically focusing on campaigns and their associated budget allocations. It takes input data related to ad sets and their budget types, and then assigns a corrected budget value at the campaign level to a dimension called “Meta ABO Budget”. Additionally, it labels the campaign as using an ABO Budget by setting the “Budget Level” dimension to “ABO”. The script also maps ad accounts to specific names based on predefined rules, ensuring that each account is correctly identified and categorized. This process helps in organizing and structuring budget data for better analysis and reporting, particularly in the context of Structured Budget Allocation (SBA).
Walking Through the Code
- Account Mapping Function:
- The
get_account
function maps ad account names to specific identifiers. It checks for specific keywords in the ad account name and returns a corresponding mapped name. If no match is found, it returns ‘Unknown’.
- The
- Data Preparation:
- The script reads input data into a DataFrame named
inputDf
. This data includes various columns related to ad sets and campaigns.
- The script reads input data into a DataFrame named
- Account Column Creation:
- A new column ‘Account’ is created in
inputDf
by applying theget_account
function to the ‘Ad Account’ column. This maps each ad account to its corresponding identifier.
- A new column ‘Account’ is created in
- Data Aggregation:
- The script groups the data by ‘Publisher Campaign ID’ and aggregates values such as ‘Campaign Name’, ‘Account’, and ‘Ad Set Daily Budget $’. The aggregated data is stored in a new DataFrame called
outputDf
.
- The script groups the data by ‘Publisher Campaign ID’ and aggregates values such as ‘Campaign Name’, ‘Account’, and ‘Ad Set Daily Budget $’. The aggregated data is stored in a new DataFrame called
- Column Renaming and Budget Level Assignment:
- The columns in
outputDf
are renamed to match the required output format. A new column ‘Budget Level’ is added with a constant value ‘ABO’, indicating the budget level type.
- The columns in
- Filtering Unknown Accounts:
- Rows with ‘Account’ set to ‘Unknown’ are filtered out from
outputDf
, ensuring only recognized accounts are included in the final output.
- Rows with ‘Account’ set to ‘Unknown’ are filtered out from
Vitals
- Script ID : 587
- Client ID / Customer ID: 1306926715 / 60270103
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Budget Level, Meta ABO Budget
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Chris Jetton (cjetton@marinsoftware.com)
- Created by Chris Jetton on 2023-12-14 19:20
- Last Updated by Chris Jetton on 2024-01-12 00:40
> 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
##
## name: ABO Budget Assignment
## description: assigns values to Meta ABO Budget and Budget Level dimensions if applicable
##
##
## author: Chris Jetton
## created: 2023-12-07
##
def get_account(ad_account):
if 'South Carolina 22' in ad_account:
return 'South Carolina 22 - Meta'
elif 'Engage WI' in ad_account:
return 'Engage WI - Meta'
elif 'Indiana22' in ad_account:
return 'Indiana 22 - Meta'
elif 'Engage NH' in ad_account:
return 'NH - Meta'
elif 'Graduation Alliance' in ad_account:
return 'Graduation Alliance - Meta'
elif 'Kansas 20' in ad_account:
return 'KANSAS 20 - Meta'
elif 'Arizona21' in ad_account:
return 'Arizona 21 - Meta'
elif 'Michigan23' in ad_account:
return 'Michigan23+ - Meta'
elif 'Arkansas 21' in ad_account:
return 'Arkansas 21+ - Meta'
elif 'AchievePoint' in ad_account:
return 'AchievePoint Career Academy - Meta'
elif 'American Academy' in ad_account:
return 'The American Academy (new) - Meta'
elif 'Engage NM' in ad_account:
return 'Engage NM - Meta'
elif 'Engage SC' in ad_account:
return 'Engage SC - Meta'
elif 'Engage MI' in ad_account:
return 'Engage MI - Meta'
elif 'Engage AZ' in ad_account:
return 'Engage AZ - Meta'
elif 'Engage GA' in ad_account:
return 'Engage GA - Meta'
elif 'Engage OH' in ad_account:
return 'Engage OH - Meta'
elif 'Missouri 21' in ad_account:
return 'Missouri 21+ - Meta'
else:
return 'Unknown'
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
# Output columns and initial values
RPT_COL_AD_SET_NAME = 'Ad Set Name'
RPT_COL_AD_ACCOUNT = 'Ad Account'
RPT_COL_CAMPAIGN_NAME = 'Campaign Name'
RPT_COL_PUBLISHER_CAMPAIGN_ID = 'Publisher Campaign ID'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_CAMPAIGN_BUDGET_TYPE = 'Campaign Budget Type'
RPT_COL_CAMPAIGN_DAILY_BUDGET = 'Campaign Daily Budget $'
RPT_COL_PUBLISHER_AD_SET_ID = 'Publisher Ad Set ID'
RPT_COL_AD_SET_STATUS = 'Ad Set Status'
RPT_COL_AD_SET_BUDGET_TYPE = 'Ad Set Budget Type'
RPT_COL_AD_SET_DAILY_BUDGET = 'Ad Set Daily Budget $'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_META_ABO_BUDGET = 'Meta ABO Budget'
BULK_COL_BUDGET_LEVEL_ABO = 'Budget Level'
# Create a new column 'Account' using the get_account function
inputDf['Account'] = inputDf['Ad Account'].apply(get_account)
# Group by Campaign ID, aggregate the values, and create the outputDf
outputDf = inputDf.groupby('Publisher Campaign ID').agg({
'Campaign Name': 'first',
'Account': 'first',
'Ad Set Daily Budget $': 'sum'
}).reset_index()
# Rename columns as per your requirements
outputDf.rename(columns={
'Campaign Name': 'Campaign',
# 'Publisher Campaign ID': 'Campaign',
'Account': 'Account',
'Ad Set Daily Budget $': 'Meta ABO Budget'
}, inplace=True)
# Add Budget Level column
outputDf['Budget Level'] = 'ABO'
# Filter out rows with Account = 'Unknown'
outputDf = outputDf[outputDf['Account'] != 'Unknown']
Post generated on 2024-11-27 06:58:46 GMT