Script 1515: Pacing Daily Budget Alert Checked Status
Purpose
The Python script filters and processes campaign data to update daily budget alerts for campaigns with a “Checked” status.
To Elaborate
The Python script is designed to manage and update daily budget alerts for advertising campaigns. It processes a dataset containing various campaign details, focusing on campaigns that have not ended and have specific traffic conditions. The script updates the daily budget for these campaigns based on a recommended value and sets the pacing calculation date to the current date. It then filters the campaigns further to include only those with a “Checked” status in the daily budget alert column. The final output consists of selected columns, including account, campaign, daily budget, and a cleared daily budget alert status, ready for further use or display.
Walking Through the Code
- Data Filtering:
- The script begins by filtering out campaigns that have ended, using the
RPT_COL_AUTO_PACING_CYCLE_THRESHOLD
column. - It further narrows down the dataset to include only campaigns with “Traffic” in the
RPT_COL_SBA_TRAFFIC
column.
- The script begins by filtering out campaigns that have ended, using the
- Data Processing:
- For the filtered campaigns, the script updates the
RPT_COL_DAILY_BUDGET
with values fromRPT_COL_RECOMMENDED_DAILY_BUDGET
. - It sets the
RPT_COL_PACING_CALCULATION_DATE
to the current date.
- For the filtered campaigns, the script updates the
- Final Filtering and Output Preparation:
- The script filters the dataset to include only campaigns where
RPT_COL_DAILY_BUDGET_ALERT
is “Checked”. - It prepares the final output by creating new columns for account, campaign, and daily budget, and clears the “Checked” status in the
RPT_COL_DAILY_BUDGET_ALERT
. - The final output is a DataFrame with selected columns, ready for display or further processing.
- The script filters the dataset to include only campaigns where
Vitals
- Script ID : 1515
- Client ID / Customer ID: 1306928345 / 60270139
- Action Type: Bulk Upload (Preview)
- 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 2024-11-11 22:58
- Last Updated by Arayla Caldwell on 2024-11-11 22:58
> 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]
filteredDf.loc[:, RPT_COL_PACING_CALCULATION_DATE] = today
# 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] = ''
# 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 2024-11-27 06:58:46 GMT