Script 337: Budget Alert
Purpose
Python script to tag campaigns based on the comparison between the publisher cost and the daily budget.
To Elaborate
The Python script aims to tag campaigns based on the comparison between the publisher cost and the daily budget. If the publisher cost is less than half of the daily budget, the campaign is tagged as “Low Spend.” If the publisher cost is greater than the threshold of 1.2 times the daily budget, the campaign is tagged as “High Spend.” The script modifies the input dataframe by adding a column for the budget alert and outputs the modified dataframe.
Walking Through the Code
- The script calculates the ratio between the publisher cost and the daily budget by dividing the “Pub. Cost $” column by the “Daily Budget” column and adds the result to a new column called “Pub Cost / Budget” in the input dataframe.
- The script sets the threshold for low spend to 0.50 (adjustable) and tags campaigns as “Low Spend” in the “Budget Alert” column if the “Pub Cost / Budget” is less than or equal to the threshold.
- The script clears the “Budget Alert” column for campaigns where the “Pub Cost / Budget” is greater than the threshold.
- The script tags campaigns as “High Spend” in the “Budget Alert” column if the “Pub Cost / Budget” is greater than 1.2 (adjustable).
- The modified input dataframe is printed.
- The script selects specific columns (RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, BULK_COL_BUDGET_ALERT) from the input dataframe and assigns them to the output dataframe.
Vitals
- Script ID : 337
- Client ID / Customer ID: 1306926711 / 60270099
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Budget Alert
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Stephen Malina (smalina@marinsoftware.com)
- Created by Stephen Malina on 2023-10-10 18:42
- Last Updated by Stephen Malina 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
#
# Tag campaign if Pub Cost is less than half of Daily Budget
#
#
# Author: Stephen Malina
# Date: 2023-10-10
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_BUDGET_ALERT = 'Budget Alert'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_BUDGET_ALERT = 'Budget Alert'
# Calculate the difference between daily budget and pub cost
inputDf['Pub Cost / Budget'] = inputDf['Pub. Cost $'] / inputDf['Daily Budget']
# Output a "Budget Alert" in case of low spend
threshold = .50 # Adjust this threshold as needed
inputDf.loc[inputDf['Pub Cost / Budget'] <= threshold, BULK_COL_BUDGET_ALERT] = "Low Spend"
inputDf.loc[inputDf['Pub Cost / Budget'] > threshold, BULK_COL_BUDGET_ALERT] = ""
inputDf.loc[inputDf['Pub Cost / Budget'] > 1.2, BULK_COL_BUDGET_ALERT] = "High Spend"
# Print the modified inputDf
print(inputDf)
cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, BULK_COL_BUDGET_ALERT]
outputDf = inputDf[cols]
Post generated on 2024-03-10 06:34:12 GMT