Script 1733: Pacing Daily Budget Alert Checked Status

Purpose:

The Python script filters and processes campaign data to identify and update daily budget alerts for campaigns marked as “Checked.”

To Elaborate

The script is designed to manage and update daily budget alerts for advertising campaigns. It begins by filtering out campaigns that have ended and focuses on those with active traffic. The script then updates the daily budget of these campaigns based on a recommended budget. It further narrows down the list to campaigns where the daily budget alert status is marked as “Checked.” The final output includes essential campaign details such as account, campaign name, daily budget, and the alert status, ensuring that only relevant campaigns are processed for budget updates.

Walking Through the Code

  1. Data Filtering:
    • The script starts by filtering out campaigns that have ended using the ‘Auto. Pacing Cycle Threshold’ column.
    • It then filters the remaining campaigns to include only those with ‘Traffic’ in the ‘SBA Traffic’ column.
  2. Budget Update:
    • For the filtered campaigns, the daily budget is updated to match the recommended daily budget.
  3. Final Selection:
    • The script further filters campaigns where the ‘Daily Budget Alert’ status is ‘Checked.’
    • It prepares the final output by creating new columns for account, campaign, daily budget, and alert status, ensuring the ‘Checked’ status is maintained.
  4. Output Preparation:
    • The script selects only the necessary columns for the final output and prints the resulting DataFrame.

Vitals

  • Script ID : 1733
  • Client ID / Customer ID: 1306927663 / 60270139
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget, Daily Budget Alert
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Arayla Caldwell (acaldwell@marinsoftware.com)
  • Created by Arayla Caldwell on 2025-02-07 22:19
  • Last Updated by Arayla Caldwell on 2025-02-07 22:19
> 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
## 
## name: Daily Budget Alert "Checked" Status 
## description:
##  
## 
## author: Jesus A. Garza
## created: 2024-07-01
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_DATE = 'Date'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_AUTO_PACING_CYCLE_START_DATE = 'Auto. Pacing Cycle Start Date'
RPT_COL_AUTO_PACING_CYCLE_END_DATE = 'Auto. Pacing Cycle End Date'
RPT_COL_AUTO_PACING_CYCLE_DAYS_ELAPSED = 'Auto. Pacing Cycle Days Elapsed'
RPT_COL_AUTO_PACING_CYCLE_DAYS_REMAINING = 'Auto. Pacing Cycle Days Remaining'
RPT_COL_AUTO_PACING_CYCLE_PACING = 'Auto. Pacing Cycle Pacing'
RPT_COL_AUTO_PACING_CYCLE_THRESHOLD = 'Auto. Pacing Cycle Threshold'
RPT_COL_TOTAL_TARGET_SPEND_PER_IMPRVIEWS = 'Total Target (Spend/Impr./Views)'
RPT_COL_TOTAL_DAYS = 'Total Days'
RPT_COL_TOTAL_DAYS_ELAPSED = 'Total Days Elapsed'
RPT_COL_TOTAL_PACING = 'Total Pacing'
RPT_COL_DELIVERY_STATUS = 'Delivery Status'
RPT_COL_RECOMMENDED_DAILY_BUDGET = 'Recommended Daily Budget'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PACING_CALCULATION_DATE = 'Pacing Calculation Date'
RPT_COL_SOCIAL_BUDGET = 'Social Budget'
RPT_COL_SOCIAL_BUDGET_UPDATE_STATUS = 'Social Budget Update Status'
RPT_COL_AUTO_PACING_CYCLE_PUB_COST = 'Auto. Pacing Cycle Pub. Cost'
RPT_COL_AUTO_PACING_CYCLE_IMPR = 'Auto. Pacing Cycle Impr.'
RPT_COL_AUTO_PACING_CYCLE_CLICKS = 'Auto. Pacing Cycle Clicks'
RPT_COL_AUTO_PACING_CYCLE_VIEWS = 'Auto. Pacing Cycle Views'
RPT_COL_SBA_TRAFFIC = 'SBA Traffic'
RPT_COL_DAILY_BUDGET_ALERT = 'Daily Budget Alert'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_DAILY_BUDGET_ALERT = 'Bulk Daily Budget Alert'

# First filter: Exclude campaigns with 'Campaign Ended'
campaigns_not_ended = inputDf[inputDf[RPT_COL_AUTO_PACING_CYCLE_THRESHOLD] != 'Campaign Ended']

# Second filter: From the remaining, only include those where SBA Traffic is 'Traffic'
filteredDf = campaigns_not_ended[campaigns_not_ended[RPT_COL_SBA_TRAFFIC] == 'Traffic']

# Apply necessary operations on filteredDf
filteredDf.loc[:, RPT_COL_DAILY_BUDGET] = filteredDf[RPT_COL_RECOMMENDED_DAILY_BUDGET]


# Filter to include only campaigns where DAILY_BUDGET_ALERT is 'Checked'
outputDf = filteredDf[filteredDf[RPT_COL_DAILY_BUDGET_ALERT] == 'Checked'].copy()

# Create new columns for output and clear the 'Checked' value in 'Bulk Daily Budget Alert'
outputDf[BULK_COL_ACCOUNT] = outputDf[RPT_COL_ACCOUNT]
outputDf[BULK_COL_CAMPAIGN] = outputDf[RPT_COL_CAMPAIGN]
outputDf[BULK_COL_DAILY_BUDGET] = outputDf[RPT_COL_DAILY_BUDGET]
outputDf[RPT_COL_DAILY_BUDGET_ALERT] = 'Checked'

# Select only the new columns for the final output
outputDf = outputDf[[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_DAILY_BUDGET, RPT_COL_DAILY_BUDGET_ALERT]]

# Assuming you want to display or utilize outputDf
print(outputDf)

Post generated on 2025-03-11 01:25:51 GMT

comments powered by Disqus