Script 577: SBA Check budget spent

Purpose

The Python script identifies campaigns with significant budget overspend or underspend by comparing publication costs to daily budgets.

To Elaborate

The Python script is designed to analyze advertising campaign data to identify campaigns that have significantly deviated from their allocated daily budgets. It calculates the percentage difference between the actual publication costs and the daily budget for each campaign. The script then filters out campaigns that are not actively trafficking, are marked as read-only, have no spending, or are not currently active. Finally, it focuses on campaigns where the budget deviation is 50% or more, either overspent or underspent, to highlight significant discrepancies that may require attention or adjustment.

Walking Through the Code

  1. Data Preparation
    • The script begins by importing the necessary data from a primary data source, which includes columns for campaign details such as publication cost, daily budget, and campaign status.
    • It calculates the percentage difference between the publication cost and the daily budget for each campaign, storing this in a new column called ‘Difference_Percentage’.
  2. Data Filtering
    • The script filters out campaigns that are not actively trafficking by checking the ‘SBA Traffic’ column.
    • It further filters out campaigns marked as read-only and those with no publication cost.
    • Only campaigns with an ‘Active’ status are retained for further analysis.
    • Finally, it filters campaigns where the absolute value of the ‘Difference_Percentage’ is 50% or more, indicating significant budget discrepancies.
  3. Output
    • The filtered data, which highlights campaigns with significant budget deviations, is stored in outputDf and printed for review.

Vitals

  • Script ID : 577
  • Client ID / Customer ID: 1306923673 / 60269245
  • Action Type: Email Report
  • Item Changed: None
  • Output Columns:
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jonathan Reichl (jreichl@marinsoftware.com)
  • Created by Jonathan Reichl on 2023-12-08 16:30
  • Last Updated by Jonathan Reichl on 2023-12-14 13:49
> 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
##
## name: SBA_Check_budget_spent
## description:
##  
## 
## author: 
## created: 2023-12-08
## 

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_PUB_COST = 'Pub. Cost $'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_SBA_BUCKET_NAME = 'SBA Bucket Name'
RPT_COL_SBA_TRAFFIC = 'SBA Traffic'
RPT_COL_SBA_READ_ONLY = 'SBA Read Only'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'

# output columns and initial values
 
  
 
# user code start here
print(tableize(inputDf))

inputDf['Difference_Percentage'] = ((inputDf[RPT_COL_PUB_COST] - inputDf[RPT_COL_DAILY_BUDGET]) / inputDf[RPT_COL_DAILY_BUDGET]) * 100

# filter rows which arnt trafficing
filtered_df = inputDf[inputDf[RPT_COL_SBA_TRAFFIC] != 0]
#filter rows that are readonly
filtered_df = filtered_df[filtered_df[RPT_COL_SBA_READ_ONLY] == 0]
#filter rows with no spend
filtered_df = filtered_df[filtered_df[RPT_COL_PUB_COST] != 0]
#Finter paused rows 
filtered_df = filtered_df[filtered_df[RPT_COL_CAMPAIGN_STATUS] == 'Active']
#Filter rows where the dif is <50%
filtered_df = filtered_df[abs(filtered_df['Difference_Percentage']) >= 50]

outputDf = filtered_df

print (tableize(outputDf))

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

comments powered by Disqus