Script 231: increase daily budget

Purpose

Python script to increase the daily budget for campaigns if the daily spend exceeds 60% of the daily budget.

To Elaborate

The Python script aims to automatically increase the daily budget for campaigns if the daily spend exceeds 60% of the daily budget. This helps ensure that campaigns have enough budget to continue running effectively and reach their goals. The script identifies campaigns that meet the criteria and calculates the new daily budget based on a 20% increase. The updated daily budget is then applied to the campaigns in the output file.

Walking Through the Code

  1. Define column constants for campaign, account, pub. cost, and daily budget.
  2. Set the value for the daily budget column in the output dataframe.
  3. Get the current date and time.
  4. Print the input dataframe in a table format.
  5. Create new column names for the updated daily budget and the 60% of the old daily budget.
  6. Set the values for the 60% of the old daily budget column based on the calculation: old daily budget * 0.6.
  7. Identify campaigns where the pub. cost is greater than or equal to 60% of the old daily budget and set the new daily budget column to the calculation: old daily budget * 1.2.
  8. Print the updated input dataframe in a table format.
  9. Copy the new daily budget values from the input dataframe to the output dataframe.
  10. Filter the output dataframe to only include campaigns with a changed strategy (new daily budget is not null and different from the current daily budget).
  11. Return the final output dataframe.

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-05-15 07:44:05 GMT

comments powered by Disqus