Script 1453: ASSIGN KW PORTFOLIO

Purpose

The Python script transfers values from the “Portfolio” column to the “Amazon Portfolio” column in a dataset.

To Elaborate

The Python script is designed to automate the process of updating a dataset by copying values from one specific column, “Portfolio,” to another column, “Amazon Portfolio.” This task is essential for ensuring that the “Amazon Portfolio” dimension accurately reflects the data contained in the “Portfolio” column. The script is straightforward and focuses on data manipulation within a DataFrame, which is a common data structure used in Python for handling tabular data. The script is likely used in a business context where maintaining accurate and up-to-date portfolio information is crucial, such as in financial reporting or marketing campaign management.

Walking Through the Code

  1. Data Preparation
    • The script begins by defining the primary data source, inputDf, which is a DataFrame containing the data to be processed.
    • It specifies the relevant column names, such as ‘Campaign’, ‘Account’, ‘Portfolio’, and ‘Amazon Portfolio’, which are used in the data manipulation process.
  2. Processing Function
    • A function named process is defined to handle the main task of the script.
    • Inside this function, the input DataFrame is copied to a new DataFrame, outputDf, to preserve the original data.
    • The script then assigns the values from the “Portfolio” column to the “Amazon Portfolio” column within outputDf.
  3. Execution
    • The process function is called with inputDf as its argument, and the resulting DataFrame, outputDf, contains the updated data.
    • The script concludes by printing the modified DataFrame, which is useful for verifying that the data has been correctly updated.

Vitals

  • Script ID : 1453
  • Client ID / Customer ID: 1306927459 / 50395
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Amazon Portfolio
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jeremy Brown (jbrown@marinsoftware.com)
  • Created by Jeremy Brown on 2024-10-24 14:32
  • Last Updated by Jeremy Brown on 2024-10-24 14:33
> 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
30
31
32
33
##
## Name: Insert Portfolio into Amazon Portfolio
## description: Insert the value from the "Portfolio" column into the "Amazon Portfolio" dimension column.
## 
## author: Jeremy Brown 
## created: 2024-10-24
##

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_PORTFOLIO = 'Portfolio'
RPT_COL_AMAZON_PORTFOLIO = 'Amazon Portfolio'

# Function to process the input DataFrame and return the output DataFrame
def process(inputDf):
    # Copy the input DataFrame to the output DataFrame
    outputDf = inputDf.copy()

    # Insert the value from the "Portfolio" column into the "Amazon Portfolio" column
    outputDf[RPT_COL_AMAZON_PORTFOLIO] = outputDf[RPT_COL_PORTFOLIO]
    
    # Print the changed data for debugging
    print(outputDf)

    return outputDf

# Trigger the main process
outputDf = process(inputDf)

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus