Script 475: SCRIPT Populate NTB Uplift Dimension

Purpose

The Python script processes marketing data to determine and populate the “NTB Uplift” value based on specific business conditions.

To Elaborate

The script is designed to analyze marketing data and determine the “NTB Uplift” for specific advertising strategies. It evaluates data from a primary source, applying business rules to identify when certain conditions are met for “Sponsored Brand Test” strategies. The conditions involve checking if the revenue is greater than zero, the Return on Advertising Spend (ROAS) exceeds a specified threshold, and the percentage of orders new to the brand over a 14-day period is above 50%. If these conditions are satisfied, the script calculates the “NTB Uplift” as a percentage increase over the 50% threshold and updates the data accordingly. This process helps in identifying and quantifying the uplift in new-to-brand orders for specific advertising strategies.

Walking Through the Code

  1. Initialization and Data Setup
    • The script begins by defining a dictionary MATCH_TYPE to categorize match types as ‘exact’, ‘phrase’, or ‘broad’.
    • It retrieves the primary data source into inputDf and defines several column names for use in processing.
  2. Data Processing Function
    • A function process is defined to handle the main logic of determining the “NTB Uplift”.
    • Two conditions (condition1 and condition2) are established to check if the strategy is either ‘Sponsored Brand Test - Watch’ or ‘Sponsored Brand Test - iPad’, with specific thresholds for revenue, ROAS, and percentage of new-to-brand orders.
    • The script initializes the ‘NTB Uplift’ column as empty and updates it where either condition is met, calculating the uplift percentage over the 50% threshold.
  3. Execution and Output
    • The process function is called with inputDf to apply the conditions and calculate the “NTB Uplift”.
    • The resulting data is stored in outputDf, which is then printed to display the updated information.

Vitals

  • Script ID : 475
  • Client ID / Customer ID: 1306926773 / 50395
  • Action Type: Bulk Upload
  • Item Changed: Keyword
  • Output Columns: Account, Campaign, Group, Keyword, Match Type, NTB Uplift
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jeremy Brown (jbrown@marinsoftware.com)
  • Created by Jeremy Brown on 2023-11-03 15:00
  • Last Updated by Jeremy Brown 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
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
##
## name: SCRIPT: Populate NTB Uplift Dimension
## description:
##  
## 
## author: 
## created: 2023-11-03
## 

MATCH_TYPE = {
  'EXACT': 'exact',
  'PHRASE': 'phrase',
  'BROAD': 'broad',
}
today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_GROUP = 'Group'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_TYPE = 'Campaign Type'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_CLICKS = 'Clicks'
RPT_COL_REVENUE = 'Revenue $'
RPT_COL_ROAS = 'ROAS'
RPT_COL_ORDERS_NEW_TO_BRAND_14_DAY = '% Orders New To Brand (14 Day)'
RPT_COL_SALES_NEW_TO_BRAND_14_DAY = '% Sales New To Brand (14 Day)'
RPT_COL_NTB_UPLIFT = 'NTB Uplift'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_NTB_UPLIFT = 'NTB Uplift'
outputDf[BULK_COL_NTB_UPLIFT] = "<<YOUR VALUE>>"

# user code start here
print(tableize(inputDf))

# Function to process the data
def process(inputDf):

    # Define the conditions for setting 'NTB Uplift' to 'YES'
    condition1 = (inputDf['Strategy'] == 'Sponsored Brand Test - Watch') & (inputDf['Revenue $'] > 0.00) & (inputDf['ROAS'] > 11) & (inputDf['% Orders New To Brand (14 Day)'] > 0.5)
    condition2 = (inputDf['Strategy'] == 'Sponsored Brand Test - iPad') & (inputDf['Revenue $'] > 0.00) & (inputDf['ROAS'] > 14) & (inputDf['% Orders New To Brand (14 Day)'] > 0.5)

    # Apply the conditions to set 'NTB Uplift' to 'YES' where applicable
    inputDf['NTB Uplift'] = ''
    inputDf.loc[condition1 | condition2, 'NTB Uplift'] = ((inputDf['% Orders New To Brand (14 Day)'] -0.5)*100).apply(lambda x: int(round(x, 0)))

    return inputDf

# Trigger the main process
outputDf = process(inputDf)

print(tableize(outputDf))

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus