Script 95: SBA cushion
Purpose
The script adjusts SBA targets by applying a target factor to the raw target values.
To Elaborate
The Python script is designed to adjust Structured Budget Allocation (SBA) targets by multiplying the raw target values with a specified target factor. This adjustment is necessary to ensure that the budget allocations are aligned with the desired financial strategies or constraints. The script processes input data, calculates the new SBA budget targets, and filters the results to include only those campaigns where the target has changed. This ensures that only relevant updates are made, optimizing the budget allocation process.
Walking Through the Code
- Initialization and Setup
- The script begins by defining several constants that represent column names used in the input and output data frames. These constants are used to ensure consistency and readability throughout the code.
- Temporary Field Initialization
- A temporary field named ‘TMP_FIELD’ is initialized in the output data frame and set to
NaN
. This field is used to store intermediate calculations of the new SBA budget targets.
- A temporary field named ‘TMP_FIELD’ is initialized in the output data frame and set to
- Calculation of New SBA Budget Target
- The script calculates the new SBA budget target by multiplying the raw target values (
RPT_COL_SBA_RAWTARGET
) with the target factor (RPT_COL_SBA_TARGETFACTOR
). The result is stored in the ‘TMP_FIELD’ of the input data frame.
- The script calculates the new SBA budget target by multiplying the raw target values (
- Rounding the Calculated Values
- The calculated values in ‘TMP_FIELD’ are rounded to the nearest whole number to ensure that the budget targets are practical and easy to manage.
- Updating the Output Data Frame
- The new SBA budget targets are set in the output data frame by copying the rounded values from ‘TMP_FIELD’ to the corresponding column (
BULK_COL_SBA_BUDGETMODELTARGET
).
- The new SBA budget targets are set in the output data frame by copying the rounded values from ‘TMP_FIELD’ to the corresponding column (
- Filtering for Changed Targets
- The script filters the output data frame to include only those campaigns where the SBA target has changed. This is done by checking for non-null values in ‘TMP_FIELD’ and ensuring that the new target differs from the existing one. This step ensures that only necessary updates are included in the final output.
Vitals
- Script ID : 95
- Client ID / Customer ID: 1306923673 / 60269245
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, SBA Budget Model Target
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-05-12 12:46
- Last Updated by Jonathan Reichl 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_SBA_BUCKETNAME = 'SBA Bucket Name'
RPT_COL_SBA_RAWTARGET = 'SBA Raw Target'
RPT_COL_SBA_TARGETFACTOR = 'SBA Target Factor'
RPT_COL_SBA_BUDGETMODELTARGET = 'SBA Budget Model Target'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_SBA_BUDGETMODELTARGET = 'SBA Budget Model Target'
#outputDf[BULK_COL_ACCOUNT] = inputDf[RPT_COL_ACCOUNT]
# blank out tmp field
outputDf['TMP_FIELD'] = np.nan
# calculate new sba budget target
inputDf['TMP_FIELD'] = inputDf[RPT_COL_SBA_TARGETFACTOR] * inputDf[RPT_COL_SBA_RAWTARGET]
#round new value
inputDf['TMP_FIELD'] = inputDf['TMP_FIELD'].round(0)
# set new sba target in output
outputDf.loc[:,BULK_COL_SBA_BUDGETMODELTARGET] = inputDf.loc[:, 'TMP_FIELD']
# only include campaigns with changed target in bulk file
outputDf = outputDf[ inputDf['TMP_FIELD'].notnull() & (inputDf[BULK_COL_SBA_BUDGETMODELTARGET] != inputDf['TMP_FIELD']) ]
Post generated on 2024-11-27 06:58:46 GMT