Script 1265: 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 Python script is designed to manage and update daily budget alerts for marketing campaigns. It processes data to filter out campaigns that have ended and focuses on those with active traffic. The script specifically targets campaigns where the daily budget alert status is marked as “Checked.” By doing so, it ensures that only relevant campaigns are considered for budget updates. The script then updates the daily budget based on recommended values and prepares the data for further use or display. This process helps in maintaining an organized and efficient budget allocation system for ongoing campaigns, ensuring that budget alerts are accurately reflected and managed.

Walking Through the Code

  1. 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 data to include only those campaigns where the RPT_COL_SBA_TRAFFIC is marked as ‘Traffic’.
  2. Budget Update:
    • For the filtered campaigns, the script updates the RPT_COL_DAILY_BUDGET with values from RPT_COL_RECOMMENDED_DAILY_BUDGET.
  3. Final Filtering and Output Preparation:
    • The script filters the data again to include only campaigns where RPT_COL_DAILY_BUDGET_ALERT is ‘Checked’.
    • It creates new columns for the output, copying relevant data from the filtered DataFrame.
    • The final output DataFrame is prepared with selected columns for further use or display.

Vitals

  • Script ID : 1265
  • Client ID / Customer ID: 1306927181 / 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: Jesus Garza (jgarza@marinsoftware.com)
  • Created by Jesus Garza on 2024-07-09 00:34
  • Last Updated by ascott@marinsoftware.com on 2024-09-04 14:37
> 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 2024-11-27 06:58:46 GMT

comments powered by Disqus