Script 181: SBA Traffic Alignment
Purpose
The script ensures that the traffic dimension is consistently aligned across each SBA bucket by setting all campaigns in a bucket to the maximum traffic value found within that bucket.
To Elaborate
The Python script is designed to maintain consistency in traffic allocation across different campaigns within the same SBA bucket. When a campaign within a bucket is set to a traffic value of 1, the script ensures that all other campaigns in that bucket are also set to 1. This alignment is crucial for maintaining uniformity in traffic distribution, which can be important for budgeting and resource allocation purposes. The script processes input data to identify the maximum traffic value within each bucket and applies this value to all campaigns in that bucket, ensuring that the traffic dimension is uniformly aligned.
Walking Through the Code
- Data Preparation
- The script begins by filling any missing values in the
RPT_COL_SBA_TRAFFIC
column with 0 to ensure there are no null values that could disrupt calculations. - It then converts the
RPT_COL_SBA_TRAFFIC
column to integers, preparing the data for numerical operations.
- The script begins by filling any missing values in the
- Grouping and Calculation
- The script groups the input data by the
RPT_COL_SBA_BUCKETNAME
column and calculates the maximum value ofRPT_COL_SBA_TRAFFIC
for each group. This step identifies the highest traffic value within each SBA bucket.
- The script groups the input data by the
- Data Merging and Alignment
- The script merges the original input data with the grouped data to append the maximum traffic value (
SBA Traffic_max
) to each row, based on the SBA bucket. - It updates the
BULK_COL_SBA_TRAFFIC
column in the output DataFrame with these maximum values, ensuring all campaigns in a bucket have the same traffic value.
- The script merges the original input data with the grouped data to append the maximum traffic value (
- Filtering
- Finally, the script filters the output DataFrame to include only those rows where the original traffic value differs from the maximum traffic value, highlighting changes made by the script.
Vitals
- Script ID : 181
- Client ID / Customer ID: 1306923673 / 60269245
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, SBA Traffic
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-06-09 10:18
- 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_SBA_BUCKETNAME = 'SBA Bucket Name'
RPT_COL_SBA_TRAFFIC = 'SBA Traffic'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_SBA_TRAFFIC = 'SBA Traffic'
outputDf[BULK_COL_SBA_TRAFFIC] = "<<YOUR VALUE>>"
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))
inputDf[RPT_COL_SBA_TRAFFIC].fillna(0, inplace=True)
inputDf[RPT_COL_SBA_TRAFFIC] = inputDf[RPT_COL_SBA_TRAFFIC].astype(int)
# Group by 'RPT_COL_CAMPAIGN' and calculate the maximum value of 'RPT_COL_SBA_TRAFFIC'
grouped = inputDf.groupby(RPT_COL_SBA_BUCKETNAME)[RPT_COL_SBA_TRAFFIC].max().reset_index()
inputDf = inputDf.merge(grouped, on= RPT_COL_SBA_BUCKETNAME, how='left', suffixes=('', '_max'))
outputDf[BULK_COL_SBA_TRAFFIC] = inputDf['SBA Traffic_max']
outputDf = outputDf[ inputDf[RPT_COL_SBA_TRAFFIC] != outputDf[BULK_COL_SBA_TRAFFIC] ]
Post generated on 2024-11-27 06:58:46 GMT