Script 179: Yesterdays Cost Dimension Tagging
Purpose
The Python script updates a DataFrame by copying yesterday’s cost data from one column to another.
To Elaborate
The script is designed to process a DataFrame containing advertising campaign data, specifically focusing on cost information. It takes an input DataFrame and creates a copy of it. The primary task is to transfer the values from the ‘Pub. Cost $’ column to the ‘Yesterdays Cost’ column. This operation is likely part of a larger process to prepare data for reporting or analysis, ensuring that the cost data from the previous day is accurately reflected in the designated column for further use. The script is straightforward and focuses solely on this data transformation task without any additional logic or conditions.
Walking Through the Code
- DataFrame Copying
- The script begins by creating a copy of the input DataFrame named
outputDf
. This ensures that the original data remains unchanged while modifications are made to the copy.
- The script begins by creating a copy of the input DataFrame named
- Column Data Transfer
- The script transfers data from the ‘Pub. Cost $’ column to the ‘Yesterdays Cost’ column within the copied DataFrame. This step is crucial for updating the cost information to reflect the previous day’s data.
- Output Display
- Finally, the script uses a function
tableize
to print the modified DataFrame, allowing users to view the updated data. This step is primarily for verification and visualization purposes.
- Finally, the script uses a function
Vitals
- Script ID : 179
- Client ID / Customer ID: 1306920365 / 45606
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Yesterdays Cost
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-06-07 20:42
- Last Updated by Aaron Thomas 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PUB_COST = 'Pub. Cost $'
RPT_COL_YESTERDAYS_COST = 'Yesterdays Cost'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_YESTERDAYS_COST = 'Yesterdays Cost'
outputDf = inputDf.copy()
outputDf[BULK_COL_YESTERDAYS_COST] = outputDf[RPT_COL_PUB_COST]
print(tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT