Script 231: increase daily budget

Purpose

The script adjusts the daily budget of campaigns by increasing it by 20% if the daily spend exceeds 60% of the current daily budget.

To Elaborate

The Python script is designed to manage and optimize advertising campaign budgets by automatically increasing the daily budget when certain conditions are met. Specifically, it checks if the daily spend of a campaign exceeds 60% of its current daily budget. If this condition is satisfied, the script increases the daily budget by 20%. This adjustment helps ensure that campaigns have sufficient budget to continue running effectively throughout the day, potentially maximizing reach and performance. The script processes input data containing campaign details and outputs a modified dataset with updated budget allocations for campaigns that meet the criteria.

Walking Through the Code

  1. Initialization and Setup:
    • The script begins by defining constants for column names used in the input and output data frames. These constants help in referencing specific columns related to campaigns, accounts, publication costs, and daily budgets.
  2. Budget Calculation:
    • A new column is created in the input data frame to store the adjusted daily budget (NEW_DAILY_BUDGET). Initially, this column is filled with NaN values.
    • Another column (A60_OLD_DAILY_BUDGET) is calculated to represent 60% of the current daily budget. This value is used as a threshold to determine if the budget should be increased.
  3. Condition Check and Budget Update:
    • The script checks if the daily spend (RPT_COL_PUB_COST) is greater than or equal to 60% of the current daily budget. If true, it calculates a new daily budget by increasing the current budget by 20% and stores it in the NEW_DAILY_BUDGET column.
  4. Output Preparation:
    • The updated daily budgets are copied to the output data frame. Only campaigns with a changed budget strategy are included in the final output, ensuring that only relevant updates are applied.

Vitals

  • Script ID : 231
  • Client ID / Customer ID: 1306920543 / 60268855
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jonathan Reichl (jreichl@marinsoftware.com)
  • Created by Jonathan Reichl on 2023-07-03 09:58
  • Last Updated by Autumn Archibald on 2024-01-09 21:28
> 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'

outputDf[BULK_COL_DAILY_BUDGET] = "<<YOUR VALUE>>"

today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))

NEW_DAILY_BUDGET = BULK_COL_DAILY_BUDGET + '_new'
inputDf[NEW_DAILY_BUDGET] = numpy.nan

A60_OLD_DAILY_BUDGET = BULK_COL_DAILY_BUDGET + '_60'
inputDf[A60_OLD_DAILY_BUDGET] = numpy.nan

inputDf.loc[:, A60_OLD_DAILY_BUDGET] = inputDf.loc[:, RPT_COL_DAILY_BUDGET] * 0.6

inputDf.loc[inputDf[RPT_COL_PUB_COST] >= inputDf[A60_OLD_DAILY_BUDGET], NEW_DAILY_BUDGET] = inputDf.loc[:, RPT_COL_DAILY_BUDGET] * 1.2

print(tableize(inputDf))

# copy new strategy to output
outputDf.loc[:,BULK_COL_DAILY_BUDGET] = inputDf.loc[:, NEW_DAILY_BUDGET]

# only include campaigns with changed strategy in bulk file
outputDf = outputDf[ inputDf[NEW_DAILY_BUDGET].notnull() & (inputDf[BULK_COL_DAILY_BUDGET] != inputDf[NEW_DAILY_BUDGET]) ]

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

comments powered by Disqus