Script 1519: Dynamic Allocation Temp Traffic

Purpose

The Python script dynamically allocates temporary traffic budgets based on recommended daily budgets from input data.

To Elaborate

The Python script is designed to manage and allocate temporary traffic budgets for advertising campaigns. It processes input data containing various campaign metrics and recommendations, specifically focusing on the recommended daily budget for each campaign. The script extracts relevant information from the input data, such as account and campaign details, and uses these to populate an output DataFrame. The primary goal is to ensure that the recommended daily budgets are correctly assigned to each campaign, facilitating efficient budget management and allocation. This process is crucial for optimizing advertising spend and ensuring that campaigns are funded appropriately according to their performance and strategic importance.

Walking Through the Code

  1. Data Preparation
    • The script begins by defining the primary data source, inputDf, which contains campaign-related data.
    • It identifies the relevant columns needed for processing, such as ‘Account’, ‘Campaign’, and ‘Recommended Daily Budget’.
  2. Output DataFrame Creation
    • An empty DataFrame, outputDf, is created to store the results.
    • The script populates outputDf with ‘Account’ and ‘Campaign’ data from inputDf.
    • The ‘Daily Budget’ column in outputDf is filled with values from the ‘Recommended Daily Budget’ column in inputDf.
  3. Output and Display
    • The script prints the first few rows of outputDf to verify the data.
    • It also prints a table representation of the first few rows of inputDf for reference.

Vitals

  • Script ID : 1519
  • Client ID / Customer ID: 1306922277 / 60268979
  • 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-13 14:28
  • Last Updated by ascott@marinsoftware.com on 2024-11-13 14:30
> 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