Script 229: populate fullfunnel
Purpose
The script adjusts the “FullFunnel” strategy for marketing campaigns based on specific ratio criteria.
To Elaborate
The Python script is designed to update the “FullFunnel” strategy for marketing campaigns by evaluating a specific ratio associated with each campaign. The script applies a set of rules to determine how the “FullFunnel” value should be adjusted. If the ratio is zero, the strategy is set to ‘-10’. For ratios greater than 0.81, the strategy is adjusted to ‘-5’. If the ratio is less than 0.72 but not zero, the strategy is set to ‘5’. Ratios between 0.72 and 0.81 retain their current “FullFunnel” value. The script ensures that only campaigns with a changed strategy are included in the final output, optimizing the allocation of resources in marketing efforts.
Walking Through the Code
- Initialization and Setup
- The script begins by defining constants for column names used in the input and output dataframes.
- A placeholder value is set for the “FullFunnel” column in the output dataframe.
- Temporary Field Creation
- A temporary field is created in the input dataframe to store new “FullFunnel” values.
- This field is initially set to NaN to ensure it is blank before processing.
- Applying Business Rules
- The script applies conditional logic to update the temporary field based on the “Ratio” column:
- If the ratio is zero, the temporary field is set to ‘-10’.
- Ratios greater than 0.81 result in a value of ‘-5’.
- Ratios less than 0.72 but not zero are set to ‘5’.
- Ratios between 0.72 and 0.81 retain their existing “FullFunnel” value.
- The script applies conditional logic to update the temporary field based on the “Ratio” column:
- Updating Output Dataframe
- The new “FullFunnel” values from the temporary field are copied to the output dataframe.
- Only campaigns with a changed “FullFunnel” strategy are included in the final output, ensuring efficient updates.
Vitals
- Script ID : 229
- Client ID / Customer ID: 1306922915 / 60269133
- Action Type: Bulk Upload
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, FullFunnel
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-06-30 09:39
- Last Updated by Anton Antonov on 2024-01-05 11:27
> 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
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_RATIO = 'Ratio'
RPT_COL_FULLFUNNEL = 'FullFunnel'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_FULLFUNNEL = 'FullFunnel'
outputDf[BULK_COL_FULLFUNNEL] = "<<YOUR VALUE>>"
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))
TMP_FIELD = BULK_COL_FULLFUNNEL + '_new'
# blank out tmp field
inputDf[TMP_FIELD] = numpy.nan
inputDf.loc[ (inputDf[RPT_COL_RATIO] == 0 ) , TMP_FIELD ] = '-10'
inputDf.loc[ (inputDf[RPT_COL_RATIO] > 0.81 ) , TMP_FIELD ] = '-5'
inputDf.loc[ ((inputDf[RPT_COL_RATIO] < 0.72 ) & (inputDf[RPT_COL_RATIO] != 0 ) ), TMP_FIELD ] = '5'
inputDf.loc[ ((inputDf[RPT_COL_RATIO] >= 0.72 ) & (inputDf[RPT_COL_RATIO] <= 0.81 ) ), TMP_FIELD ] = inputDf[RPT_COL_FULLFUNNEL]
# copy new strategy to output
outputDf.loc[:,BULK_COL_FULLFUNNEL] = inputDf.loc[:, TMP_FIELD]
# only include campaigns with changed strategy in bulk file
outputDf = outputDf[ (inputDf[RPT_COL_FULLFUNNEL] != inputDf[TMP_FIELD]) ]
Post generated on 2024-11-27 06:58:46 GMT