Script 1065: Script Campaign CPA This Quarter Set
Purpose
The script updates the ‘Campaign CPA This Quarter’ column with the current quarter’s CPA values for each campaign.
To Elaborate
The Python script is designed to manage and update campaign data by setting the ‘Campaign CPA This Quarter’ column with the CPA (Cost Per Acquisition) values for the current quarter. This task is essential for marketing and finance teams to track and analyze the cost efficiency of their campaigns over a specific period. By automating the update of CPA values, the script ensures that the data remains current and accurate, facilitating better decision-making and budget allocation. The script operates on a dataset containing campaign information and outputs a modified version with the updated CPA values.
Walking Through the Code
- Data Source Initialization
- The script begins by defining the primary data source,
inputDf
, which is retrieved from a dictionary nameddataSourceDict
. This dictionary presumably contains various datasets, and the script selects the one labeled “1”.
- The script begins by defining the primary data source,
- Output DataFrame Preparation
- It creates a copy of the input DataFrame,
outputDf
, to preserve the original data while making modifications. This ensures that any changes are made on a separate dataset, maintaining data integrity.
- It creates a copy of the input DataFrame,
- Column Update
- The script updates the ‘Campaign CPA This Quarter’ column in the
outputDf
by copying values from the ‘All - Complete Registration - CPA’ column of theinputDf
. This operation effectively transfers the CPA values for the current quarter to the designated column for further analysis.
- The script updates the ‘Campaign CPA This Quarter’ column in the
- Output Display
- Finally, the script prints a tableized version of the
outputDf
, allowing users to visually inspect the updated data. This step is crucial for verifying that the CPA values have been correctly set in the ‘Campaign CPA This Quarter’ column.
- Finally, the script prints a tableized version of the
Vitals
- Script ID : 1065
- Client ID / Customer ID: 1306927809 / 60270355
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Campaign CPA This Quarter
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
- Created by Grégory Pantaine on 2024-05-10 15:36
- Last Updated by Grégory Pantaine on 2024-05-15 12:24
> 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
## name: Script - Campaign - CPA This Quarter - Set
##
## description: Take CPA for this Quarter and set the value in the 'Campaign CPA This Quarter' column.
## Copied & adjusted by Grég P.
## created: 2024-05-10
# Primary data source and columns
inputDf = dataSourceDict["1"]
# Output columns and initial values
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_COMPLETE_REGISTRATION_CPA = 'All - Complete Registration - CPA'
RPT_COL_CAMPAIGN_CPA_QUARTER = 'Campaign CPA This Quarter'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGN_CPA_QUARTER = 'Campaign CPA This Quarter'
# Copy input data to output
outputDf = inputDf.copy()
# Copy values from 'Strategy' column to 'SBA Strategy' column
outputDf[RPT_COL_CAMPAIGN_CPA_QUARTER] = inputDf[RPT_COL_COMPLETE_REGISTRATION_CPA]
# Print the tableized version of the output DataFrame
print(tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT