Script 203: Yesterdays Cost Dimension Tagging SightMatters
Purpose
The script updates a DataFrame by copying the ‘Pub. Cost $’ column to a new ‘Yesterdays Cost’ column.
To Elaborate
The Python script is designed to process a DataFrame by creating a new column called ‘Yesterdays Cost’ and populating it with the values from an existing column named ‘Pub. Cost $’. This operation is typically used in financial or budgetary contexts where yesterday’s costs need to be tracked or reported separately from other financial data. The script ensures that the cost data from the previous day is readily available for further analysis or reporting, which is crucial for maintaining accurate financial records and making informed budgetary decisions.
Walking Through the Code
- DataFrame Copying:
- The script begins by creating a copy of the input DataFrame named
outputDf
. This is done to preserve the original data while allowing modifications to be made to the copy.
- The script begins by creating a copy of the input DataFrame named
- Column Assignment:
- A new column, ‘Yesterdays Cost’, is added to the
outputDf
DataFrame. This column is populated with the values from the ‘Pub. Cost $’ column, effectively duplicating the cost data for further use.
- A new column, ‘Yesterdays Cost’, is added to the
- Output Display:
- The modified DataFrame is then printed in a tabular format using the
tableize
function, which is likely a utility function for displaying DataFrame contents in a readable manner.
- The modified DataFrame is then printed in a tabular format using the
Vitals
- Script ID : 203
- Client ID / Customer ID: 1306915623 / 45606
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Yesterdays Cost
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Autumn Archibald (aarchibald@marinsoftware.com)
- Created by Autumn Archibald on 2023-06-16 16:04
- Last Updated by Autumn Archibald 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