Script 1685: Script Strategies Ascend Campaign Mapping

Purpose:

The Python script assigns a specific strategy to campaigns based on the account name when the strategy is initially unassigned.

To Elaborate

The script is designed to update the strategy for marketing campaigns based on the account name when the strategy is marked as “Unassigned.” It uses a predefined mapping between account names and their corresponding strategies. This ensures that each campaign is correctly tagged with the appropriate strategy, facilitating better organization and management of marketing efforts. The script processes data from a primary data source, applies the mapping logic, and outputs the updated strategy information for each campaign.

Walking Through the Code

  1. Data Source Initialization:
    • The script begins by defining the primary data source and specifying the columns that will be used, such as ‘Campaign’, ‘Account’, ‘Campaign ID’, and ‘Strategy’.
  2. Mapping Definition:
    • A dictionary named ACCOUNT_STRATEGY_MAPPING is created to map specific account names to their corresponding strategies. This dictionary serves as the basis for updating strategies when they are unassigned.
  3. Strategy Update Function:
    • A function update_strategy is defined to check if the strategy is ‘Unassigned’ and if the account exists in the mapping. If both conditions are met, it returns the mapped strategy; otherwise, it retains the original strategy.
  4. Applying the Strategy Update:
    • The script applies the update_strategy function to each row in the output DataFrame, updating the ‘Strategy’ column based on the account name and current strategy status.
  5. Output:
    • The script concludes by printing the first few rows of the input and output DataFrames to verify the changes made to the strategy column.

Vitals

  • Script ID : 1685
  • Client ID / Customer ID: 1306927585 / 60270327
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Strategy, Campaign ID
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
  • Created by Grégory Pantaine on 2025-02-05 12:47
  • Last Updated by Grégory Pantaine on 2025-02-05 12:50
> 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
##
## name: Script - Strategies Ascend Campaign Mapping 
## description: Tags Strategy Value based on the Account name, if campaign is in Unassigned strategy
## 
## author: G Pantaine with help from ChatGPT.
## created: 2025-02-05
## 


# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGNID = 'Campaign ID'
RPT_COL_STRATEGY = 'Strategy'


# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGNID = 'Campaign ID'
BULK_COL_STRATEGY = 'Strategy'

# Mapping account to strategy
ACCOUNT_STRATEGY_MAPPING = {
    'Google CA': 'Google CA - Ascend',
    'Google UK': 'Google UK - Ascend',
    'Google US': 'Google US - Ascend',
    'LinkedIn CA': 'LinkedIn CA - Ascend',
    'LinkedIn Global': 'LinkedIn Global - Ascend',
    'LinkedIn UK': 'LinkedIn UK - Ascend',
    'LinkedIn US': 'LinkedIn US - Ascend',
    'Microsoft Ads CA': 'Microsoft Ads CA - Ascend',
    'Microsoft ads UK': 'Microsoft ads UK - Ascend',
    'Microsoft ads US': 'Microsoft ads US - Ascend',
}

# Function to update strategy based on account
def update_strategy(account, strategy):
    if strategy == 'Unassigned' and account in ACCOUNT_STRATEGY_MAPPING:
        return ACCOUNT_STRATEGY_MAPPING[account]
    return strategy

# Apply the update strategy function
outputDf['Strategy'] = outputDf.apply(lambda row: update_strategy(row[BULK_COL_ACCOUNT], row.get('Strategy', 'Unassigned')), axis=1)

# Debug print first few rows
print(tableize(inputDf.head()))
print("\nOutput DataFrame with Updated Strategy:")
print(tableize(outputDf.head()))

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

comments powered by Disqus