Script 1771: Script Always Push Budgets

Purpose:

The Python script dynamically allocates recommended daily budgets to campaigns based on input data.

To Elaborate

The Python script is designed to automate the allocation of daily budgets for advertising campaigns. It processes data from a primary source, which includes various metrics and recommendations for each campaign. The script extracts the recommended daily budget for each campaign and constructs an output DataFrame that maps these budgets to the respective campaigns and accounts. This structured approach ensures that the budget allocation is aligned with the recommendations provided, optimizing the financial resources allocated to each campaign. The script is part of a broader system that likely involves multiple data sources and complex business rules to ensure efficient budget management across different advertising platforms.

Walking Through the Code

  1. Initialization and Data Source Setup
    • The script begins by setting up the primary data source, inputDf, which contains detailed information about campaigns, including recommended budgets.
    • It defines several column names that are used to extract and manipulate data from the input DataFrame.
  2. Output DataFrame Construction
    • An empty DataFrame, outputDf, is created to store the results of the budget allocation process.
    • The script populates this DataFrame with account and campaign information from the input data, along with the recommended daily budget for each campaign.
    • The output DataFrame is then printed to display the first few rows, providing a snapshot of the allocated budgets.
  3. User Changeable Parameters
    • The script allows for customization of the output column values, specifically the daily budget, which can be adjusted based on user requirements or additional business logic.

Vitals

  • Script ID : 1771
  • Client ID / Customer ID: 1306928641 / 60270613
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: ascott@marinsoftware.com (ascott@marinsoftware.com)
  • Created by ascott@marinsoftware.com on 2025-02-28 19:02
  • Last Updated by ascott@marinsoftware.com on 2025-03-03 15:35
> 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
71
72
73
74
##
## name: Dynamic Allocation Temp Traffic
## description:
##  
## 
## author: 
## created: 2024-11-13
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_TYPE = 'Campaign Type'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_STRATEGY_TARGET = 'Strategy Target'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_CTR = 'CTR %'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_IMPR_SHARE = 'Impr. share %'
RPT_COL_LOST_IMPR_SHARE_BUDGET = 'Lost Impr. Share (Budget) %'
RPT_COL_LOST_IMPR_SHARE_RANK = 'Lost Impr. Share (Rank) %'
RPT_COL_SHARED_BUDGET = 'Shared Budget'
RPT_COL_PUBLISHER_BID_PORTFOLIO_NAME = 'Publisher Bid Portfolio Name'
RPT_COL_PUBLISHER_BID_STRATEGY = 'Publisher Bid Strategy'
RPT_COL_PUBLISHER_TARGET_CPA = 'Publisher Target CPA'
RPT_COL_PUBLISHER_TARGET_ROAS = 'Publisher Target ROAS'
RPT_COL_UNCONSTRAINED_RECOMMENDED_CPA_PER_ROAS_TARGET = 'Unconstrained Recommended CPA/ROAS Target'
RPT_COL_RECOMMENDED_CPA_PER_ROAS_TARGET = 'Recommended CPA/ROAS Target'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_UNCONSTRAINED_RECOMMENDED_DAILY_BUDGET = 'Unconstrained Recommended Daily Budget'
RPT_COL_RECOMMENDED_DAILY_BUDGET = 'Recommended Daily Budget'
RPT_COL_RECOMMENDATION_CONSTRAINTS = 'Recommendation Constraints'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'
RPT_COL_DAILY_BUDGET_RECOMMENDATION_DATE = 'Daily Budget Recommendation Date'
RPT_COL_CPA_PER_ROAS_TARGET_RECOMMENDATION_DATE = 'CPA/ROAS Target Recommendation Date'
RPT_COL_PUBLISHER_BID_STRATEGY_SYSTEM_STATUS = 'Publisher Bid Strategy System Status'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
outputDf[BULK_COL_DAILY_BUDGET] = "<<YOUR VALUE>>"


# Assuming CLIENT_TIMEZONE is defined somewhere in your code
today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_RECOMMENDED_DAILY_BUDGET = 'Recommended Daily Budget'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'

# Create the output DataFrame
outputDf = pd.DataFrame()
outputDf[BULK_COL_ACCOUNT] = inputDf['Account']
outputDf[BULK_COL_CAMPAIGN] = inputDf['Campaign']
outputDf[BULK_COL_DAILY_BUDGET] = inputDf[RPT_COL_RECOMMENDED_DAILY_BUDGET]

# Print the first few rows of the output DataFrame
print(outputDf.head())

print(tableize(inputDf.head()))

Post generated on 2025-03-11 01:25:51 GMT

comments powered by Disqus