Script 139: Increase Campaign Daily Budget
Purpose
The script increases the daily budget for campaigns with an impression share greater than a specified percentage over the last specified number of days.
To Elaborate
The Python script is designed to automate the process of increasing the daily budget for advertising campaigns based on their performance metrics. Specifically, it targets campaigns that have an impression share exceeding a certain threshold over a defined period. The script identifies campaigns that have not had their daily budget updated recently and ensures that these campaigns are considered for budget adjustments. By doing so, it helps optimize the allocation of advertising funds to campaigns that are performing well, thereby potentially increasing their reach and effectiveness. The script uses data from a report to determine which campaigns meet the criteria for a budget increase and updates the relevant records accordingly.
Walking Through the Code
- Initial Setup and Configuration:
- The script begins by defining several constants related to campaign and account data columns.
- It assigns the current date to a variable, which is used later to determine the recency of budget updates.
- Data Preparation:
- The script checks for campaigns with no recorded date for the last budget update and creates a DataFrame (
blankDf
) for these campaigns, assigning the current date as the last updated date. - It also creates a DataFrame (
nonblankDf
) for campaigns that have a recorded last updated date, converting these dates into a format that can be used for calculations.
- The script checks for campaigns with no recorded date for the last budget update and creates a DataFrame (
- Determine Campaigns for Budget Update:
- The script calculates the number of days since the last budget update for each campaign in
nonblankDf
. - It identifies campaigns that have not been updated in more than 14 days and creates a DataFrame (
dateDf
) for these campaigns, updating their last updated date to the current date.
- The script calculates the number of days since the last budget update for each campaign in
- Merge and Output:
- The script merges the DataFrames
blankDf
anddateDf
to formoutputDf
, which contains all campaigns that need a budget update. - Finally, it prints the resulting DataFrame in a tabular format for review.
- The script merges the DataFrames
User changeable parameters include the threshold for impression share and the number of days since the last update, which determine which campaigns are eligible for a budget increase.
Vitals
- Script ID : 139
- Client ID / Customer ID: 1306924501 / 60269325
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Daily Budget, Last Updated - Daily Budget
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-05-25 18:31
- Last Updated by Byron Porter on 2023-12-06 04:01
> 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
#
# Increase Campaign Daily Budget
#
# Byron Porter
# 2023-05-26
#
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_LOST_IMPRSHAREBUDGET = 'Lost Impr. Share (Budget) %'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_LAST_UPDATEDDAILYBUDGET = 'Last Updated - Daily Budget'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_LAST_UPDATEDDAILYBUDGET = 'Last Updated - Daily Budget'
########## CONFIGURABLE PARAMS - END ##########
# Assign current date to a parameter
today = datetime.datetime.now() #.date()
# Check if RPT_COL_LAST_UPDATEDDAILYBUDGET is blank
null_check = inputDf[RPT_COL_LAST_UPDATEDDAILYBUDGET].isnull()
# Use check to create DataFrame for campaigns with no Last Updated value and assign current date
blankDf = inputDf.loc[null_check, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET, RPT_COL_LAST_UPDATEDDAILYBUDGET]]
blankDf.loc[:, RPT_COL_LAST_UPDATEDDAILYBUDGET] = today.date() # today
# Use check to create DataFrame for campaigns with a Last Updated value
nonblankDf = inputDf.loc[~null_check, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET, RPT_COL_LAST_UPDATEDDAILYBUDGET]]
# Convert date string in RPT_COL_LAST_UPDATEDDAILYBUDGET column to date object
nonblankDf['ConvertedDate'] = pd.to_datetime(inputDf[RPT_COL_LAST_UPDATEDDAILYBUDGET], format="%Y-%m-%d")
# Create temp column to show number of days since last update
nonblankDf['DaysSinceUpdate'] = (today - nonblankDf['ConvertedDate']).dt.days
# Use check to create a DataFrame of campaigns to update
diff_check = nonblankDf['DaysSinceUpdate'] > 14
dateDf = nonblankDf.loc[diff_check, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET, RPT_COL_LAST_UPDATEDDAILYBUDGET]]
dateDf.loc[:, RPT_COL_LAST_UPDATEDDAILYBUDGET] = today.date()
# Merge blankDf and dateDf to outputDf
#outputDf = pd.concat([blankDf, dateDf])
outputDf = blankDf.merge(dateDf, how='outer')
print(tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT