Script 1551: Script Last365Days Conversions

Purpose:

The script transfers Microsoft purchase conversion data into a new column labeled “Last365Days Conversions” within a dataset.

To Elaborate

The Python script is designed to process a dataset by transferring values from an existing column, which contains Microsoft purchase conversion data, into a newly created column named “Last365Days Conversions.” This operation is part of a data transformation task where the goal is to ensure that the conversion data is readily available in a specific format or structure, possibly for further analysis or reporting purposes. The script operates on a primary data source, ensuring that the new column is populated with the correct conversion values, thereby facilitating structured budget allocation (SBA) or similar financial analysis tasks.

Walking Through the Code

  1. Data Preparation
    • The script begins by setting up the primary data source, inputDf, which contains the necessary columns for processing.
    • It identifies the relevant columns, including the one for Microsoft purchase conversions (RPT_COL_CONV).
  2. Data Transformation
    • A copy of the input DataFrame is created to ensure that the original data remains unchanged.
    • The script then transfers the values from the ‘MSFT Purchase Conv.’ column to the newly defined ‘Last365Days Conversions’ column in the output DataFrame.
  3. Verification
    • To verify the transformation, the script prints the first few rows of the output DataFrame.
    • It also outputs a summary message confirming the successful addition of the new column with the transferred values.

Vitals

  • Script ID : 1551
  • Client ID / Customer ID: 1306914548 / 60268186
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Last365Days Conversions
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
  • Created by Grégory Pantaine on 2024-11-29 14:16
  • Last Updated by Grégory Pantaine on 2024-12-09 15:10
> 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: Script: Last365Days Conversions
## description: set the microsoft purchase conversion as the value in the dimension "Last365Days"
##  
## 
## author: CHatGPT & Gregory Pantaine
## created: 2024-11-29
## 

# Current date setup
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_CONV = 'MSFT Purchase Conv.'

# Output column name
OUTPUT_COL_CONVERSIONS = 'Last365Days Conversions'

# Ensure the output DataFrame includes the required column
outputDf = inputDf.copy()

# Copy values from 'Conv.' to 'Last365Days Conversions'
outputDf[OUTPUT_COL_CONVERSIONS] = inputDf[RPT_COL_CONV]

# Print the first few rows of the output to verify
print(tableize(outputDf.head()))

# Output column summary for debugging
print(f"Column '{OUTPUT_COL_CONVERSIONS}' added with values from '{RPT_COL_CONV}'")

Post generated on 2025-03-11 01:25:51 GMT

comments powered by Disqus