Script 1527: NEUN MLAWS USFL MSPGM Budget Trafficking

Purpose

The Python script automates the process of allocating and updating daily budgets for advertising campaigns based on recommended values from a data source.

To Elaborate

The script is designed to streamline the management of advertising budgets by dynamically updating daily budget allocations for various campaigns. It achieves this by extracting data from a primary data source, which includes recommended daily budget values for each campaign. The script then constructs an output DataFrame that aligns with the required format for budget updates, ensuring that each campaign’s budget is set to the recommended amount. This process helps in maintaining optimal budget distribution across campaigns, potentially improving the efficiency and effectiveness of advertising spend. The script is particularly useful for marketing teams looking to automate budget adjustments based on performance data and recommendations.

Walking Through the Code

  1. Data Source Initialization
    • The script begins by defining the primary data source, inputDf, which contains various columns related to campaign performance and recommendations.
    • Key columns include campaign identifiers and recommended daily budgets.
  2. Output DataFrame Construction
    • An empty DataFrame, outputDf, is created to store the updated budget information.
    • The script populates this DataFrame with account and campaign identifiers from the input data.
    • The daily budget for each campaign in the output DataFrame is set to the recommended daily budget from the input data.
  3. Output Verification
    • The script prints the first few rows of the outputDf to verify the updated budget allocations.
    • Additionally, it prints a table representation of the first few rows of the input data for reference.

This script allows users to automate budget updates, ensuring that campaigns are funded according to the latest recommendations, which can be adjusted by changing the input data source or the logic for budget allocation.

Vitals

  • Script ID : 1527
  • Client ID / Customer ID: 1306926629 / 60270083
  • 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 2024-11-14 19:52
  • Last Updated by ascott@marinsoftware.com on 2024-11-25 20:07
> 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
75
##
## 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 2024-11-27 06:58:46 GMT

comments powered by Disqus