Script 867: Budget Capped Campaigns

Purpose

The Python script identifies campaigns where the previous day’s spending is at least 90% of the daily budget and flags them as “Budget Capped” if certain conditions are met.

To Elaborate

The script is designed to monitor advertising campaigns by analyzing their spending relative to their daily budget. Specifically, it checks if the spending (referred to as “Pub Cost”) for the previous day reaches or exceeds 90% of the allocated daily budget. If this condition is met, and additional criteria regarding impression share loss and a metric called “iDNE” are satisfied, the campaign is flagged with a “Budget Capped” alert. This alert serves as a warning that the campaign is at risk of exceeding its budget, potentially impacting its performance. The script helps in managing and optimizing campaign budgets by providing timely alerts, allowing for adjustments to be made to prevent overspending.

Walking Through the Code

  1. Data Preparation
    • The script begins by converting the ‘iDNE’ column in the input DataFrame to numeric values, handling any errors by coercing them into NaN. This ensures that subsequent calculations involving ‘iDNE’ are performed correctly.
  2. Calculation of Ratios and Conditions
    • It calculates the ratio of ‘Pub Cost’ to ‘Daily Budget’ for each campaign and stores it in a new column ‘Pub Cost / Budget’.
    • The script also retains the ‘iDNE’ and ‘Lost Imp Share’ values for further analysis.
  3. Applying Business Rules
    • A threshold of 0.90 is set, which can be adjusted by the user if needed. This threshold determines the minimum percentage of the budget that must be spent for a campaign to be considered for a “Budget Capped” alert.
    • Campaigns are flagged with a “Budget Capped” alert if their ‘Pub Cost / Budget’ is at least 90%, ‘iDNE’ is less than 1.5, and ‘Lost Imp Share’ is greater than 10%.
  4. Output Preparation
    • The script selects relevant columns, including ‘Account’, ‘Campaign’, and ‘Budget Alert’, to create an output DataFrame that highlights campaigns with budget alerts.
    • Finally, it prints the modified DataFrame to display the results.

Vitals

  • Script ID : 867
  • Client ID / Customer ID: 247885838 / 13095968
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Budget Alert
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: smalina@marinsoftware.com (smalina@marinsoftware.com)
  • Created by Stephen Malina on 2024-03-29 16:37
  • Last Updated by Stephen Malina on 2024-04-23 20:44
> 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
#
# Tag campaign if Pub Cost for prior day is 90% of Daily Budget
#
#
# Author: Stephen Malina
# Date: 2024-03-27

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'
RPT_COL_iDNE = 'iDNE'
RPT_COL_LOST_IMP_SHARE = 'Lost Impr. Share (Budget) %'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_BUDGET_ALERT = 'Budget Alert'

# Convert the 'iDNE' column to numeric values
inputDf[RPT_COL_iDNE] = pd.to_numeric(inputDf[RPT_COL_iDNE], errors='coerce')

# Calculate the difference between daily budget and pub cost, include iDNE for consideration
inputDf['Pub Cost / Budget'] = inputDf[RPT_COL_PUB_COST] / inputDf[RPT_COL_DAILY_BUDGET]
inputDf['iDNE'] = inputDf[RPT_COL_iDNE]
inputDf['Lost Imp Share'] = inputDf[RPT_COL_LOST_IMP_SHARE]

# Output a "Budget Cap Alert" where daily spend is greater than 90% of daily budget and iDNE is less than 1.5
threshold = 0.90  # Adjust this threshold as needed
inputDf.loc[inputDf['Pub Cost / Budget'] < threshold, BULK_COL_BUDGET_ALERT] = ""
inputDf.loc[(inputDf['Pub Cost / Budget'] >= threshold) & (inputDf['iDNE'] < 1.5) & (inputDf['Lost Imp Share'] > 10), BULK_COL_BUDGET_ALERT] = "Budget Capped"

# Print the modified inputDf
print(inputDf)
cols = [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, BULK_COL_BUDGET_ALERT]
outputDf = inputDf[cols]

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus