Script 255: GAAP Profit 0 Reduce Budget 20%

Purpose

Reduce the daily budget of campaigns by 20% if the GAAP profit from the previous day is less than 0.

To Elaborate

The Python script aims to automatically reduce the daily budget of campaigns if the GAAP profit from the previous day is negative. This helps to optimize campaign spending and prevent further losses. The script identifies campaigns with negative GAAP profit and reduces their daily budget by 20%. By automating this process, it saves time and ensures that budget adjustments are made consistently based on predefined rules.

Walking Through the Code

  1. The script defines column constants for various attributes such as campaign, account, daily budget, etc.
  2. The current date is obtained using the datetime.now() function with the client’s timezone.
  3. The input dataframe is printed using the tableize() function.
  4. The input dataframe is copied to the output dataframe, including the account, campaign, and daily budget columns.
  5. The daily budget column in the output dataframe is multiplied by 0.8 to reduce it by 20%.
  6. The output dataframe is printed using the tableize() function.

Vitals

  • Script ID : 255
  • Client ID / Customer ID: 195137062 / 12017568
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Tom Lowes (tlowes@marinsoftware.com)
  • Created by Tom Lowes on 2023-07-27 14:58
  • Last Updated by Tom Lowes 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
#
# Reduce Campaign Budget if GAAP_Profit < 0 yesterday
#
#
# Author: Tom Lowes
# Date: 2023-07-27

RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_GAAP_PROFIT = 'GAAP Profit $'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'

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

# copy all input rows to output
outputDf = inputDf[[RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET]].copy()
outputDf[RPT_COL_DAILY_BUDGET] = outputDf[RPT_COL_DAILY_BUDGET]*0.8

print(tableize(outputDf))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus