Script 1777: Script Set Posting Status at Campaign Level
Purpose:
The script updates campaign-level posting statuses by mapping strategies to specific budget and bid dimensions.
To Elaborate
The Python script is designed to update the posting status of campaigns by aligning them with specific strategies and their associated budget and bid dimensions. It takes input from a primary data source containing campaign details and a reference data source that holds strategy-specific information. The script maps strategies to their corresponding posting dimensions, such as daily budgets and CPA/ROAS targets, and updates the campaign data accordingly. This ensures that each campaign is aligned with the correct strategy parameters, facilitating structured budget allocation (SBA) and efficient campaign management.
Walking Through the Code
- Data Initialization:
- The script begins by defining the primary and reference data sources, which are stored in
inputDf
andreportDf
respectively. These dataframes contain information about campaigns and strategies.
- The script begins by defining the primary and reference data sources, which are stored in
- Column Mapping:
- It sets up mappings between strategy-related columns in the reference data and their corresponding dimension columns in the output data. This mapping is crucial for updating the campaign data with the correct strategy parameters.
- Data Iteration and Update:
- The script iterates over each row in the
inputDf
to check if the strategy exists in thereportDf
. If a match is found, it updates the output dataframe with the corresponding dimension values from the reference data.
- The script iterates over each row in the
- Output Display:
- Finally, the script prints the updated output dataframe to show the changes made to the campaign posting statuses.
Vitals
- Script ID : 1777
- Client ID / Customer ID: 1306926629 / 60270083
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Campaign ID, Posting Bids (DIM), Posting CPA/ROAS Targets (DIM), Posting Daily Budgets (DIM)
- Linked Datasource: M1 Report
- Reference Datasource: M1 Report
- Owner: ascott@marinsoftware.com (ascott@marinsoftware.com)
- Created by ascott@marinsoftware.com on 2025-03-05 22:24
- Last Updated by ascott@marinsoftware.com on 2025-03-05 22:24
> 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
##
## name: Script - Set Posting Status at Campaign Level
## description:
##
##
## author:
## created: 2025-02-28
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_POSTING_BIDS_DIM = 'Posting Bids (DIM)'
RPT_COL_POSTING_CPA_PER_ROAS_TARGETS_DIM = 'Posting CPA/ROAS Targets (DIM)'
RPT_COL_POSTING_DAILY_BUDGETS_DIM = 'Posting Daily Budgets (DIM)'
# reference data source and columns
reportDf = dataSourceDict["2"] # report dataframe
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_POSTING_DAILY_BUDGETS = 'Posting Daily Budgets'
RPT_COL_POSTING_CPA_PER_ROAS_TARGETS = 'Posting CPA/ROAS Targets'
RPT_COL_POSTING_BIDS = 'Posting Bids'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_POSTING_BIDS_DIM = 'Posting Bids (DIM)'
BULK_COL_POSTING_CPA_PER_ROAS_TARGETS_DIM = 'Posting CPA/ROAS Targets (DIM)'
BULK_COL_POSTING_DAILY_BUDGETS_DIM = 'Posting Daily Budgets (DIM)'
outputDf[BULK_COL_POSTING_BIDS_DIM] = "<<YOUR VALUE>>"
outputDf[BULK_COL_POSTING_CPA_PER_ROAS_TARGETS_DIM] = "<<YOUR VALUE>>"
outputDf[BULK_COL_POSTING_DAILY_BUDGETS_DIM] = "<<YOUR VALUE>>"
# Create mappings for strategy-to-column updates
strategy_mapping = {
RPT_COL_POSTING_DAILY_BUDGETS: RPT_COL_POSTING_DAILY_BUDGETS_DIM,
RPT_COL_POSTING_CPA_PER_ROAS_TARGETS: RPT_COL_POSTING_CPA_PER_ROAS_TARGETS_DIM,
RPT_COL_POSTING_BIDS: RPT_COL_POSTING_BIDS_DIM,
}
# Iterate over the input dataframe and update reference values based on strategy
for index, row in inputDf.iterrows():
strategy = row[RPT_COL_STRATEGY]
if strategy in reportDf[RPT_COL_STRATEGY].values:
matching_rows = reportDf[reportDf[RPT_COL_STRATEGY] == strategy]
for col, dim_col in strategy_mapping.items():
if not matching_rows.empty:
outputDf.loc[index, dim_col] = matching_rows.iloc[0][col]
# Display updated output dataframe
print(outputDf.head())
# user code start here
print(tableize(inputDf.head()))
Post generated on 2025-03-11 01:25:51 GMT