Script 1003: Tagging dimension Script Campaigns F YY Brand

Purpose:

The Python script extracts and tags the “F-YY-Brand” from campaign names in a dataset, ensuring structured budget allocation.

To Elaborate

The script is designed to process a dataset containing campaign information, specifically focusing on extracting a structured tag known as “F-YY-Brand” from each campaign name. This tag is derived from the first segment of the campaign name, separated by an underscore. The script iterates through each row of the dataset, extracts the “F-YY-Brand” tag, and updates the corresponding column in the output dataset. Additionally, it ensures that any rows missing the “F-YY-Brand” value are removed from the final output, maintaining data integrity for structured budget allocation purposes.

Walking Through the Code

  1. Configurable Parameters:
    • The script begins by defining several parameters that can be adjusted by the user, such as the separator (SEP) used in campaign names and the location of the tag (TAG_LOCATION).
  2. Function Definition:
    • A function extract_fyybrand is defined to extract the “F-YY-Brand” from a campaign name. It checks for the presence of the separator and splits the name accordingly.
  3. Data Processing:
    • The script copies the input dataset to an output dataset to preserve the original data.
    • It iterates through each row of the input dataset, extracting the “F-YY-Brand” using the defined function and updating the corresponding column in the output dataset.
  4. Data Cleaning:
    • After processing, the script removes any rows from the output dataset that have missing “F-YY-Brand” values, ensuring that the final dataset is complete and ready for further analysis or reporting.
  5. Output Handling:
    • The script checks if the output dataset is empty and prints the results accordingly, providing a summary of the processed data.

Vitals

  • Script ID : 1003
  • Client ID / Customer ID: 1306927457 / 60270313
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, F-YY-Brand
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Autumn Archibald (aarchibald@marinsoftware.com)
  • Created by Autumn Archibald on 2024-04-25 20:47
  • Last Updated by Autumn Archibald on 2024-04-25 21:38
> 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
# Define the configurable parameters for the script
SEP = '_'  # Separator used in campaign names
TAG_LOCATION = 0  # First word before the first separator
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_FYYBRAND = 'F-YY-Brand'

# Function to extract F-YY-Brand from campaign name
def extract_fyybrand(campaign_name):
    if SEP in campaign_name:
        return campaign_name.split(SEP)[TAG_LOCATION]  # Extracting the first word before the first separator "_"
    else:
        return campaign_name  # If no separator is found, consider the whole campaign name as F-YY-Brand

# Copy input rows to output
outputDf = inputDf.copy()

# Loop through all rows
for index, row in inputDf.iterrows():
    campaign_name = row[RPT_COL_CAMPAIGN]

    # Extract F-YY-Brand from campaign name
    fyybrand = extract_fyybrand(campaign_name)
    print("Campaign [%s] => F-YY-Brand [%s]" % (campaign_name, fyybrand))

    # Update F-YY-Brand column
    outputDf.at[index, BULK_COL_FYYBRAND] = fyybrand

# Drop any rows with missing F-YY-Brand values
outputDf = outputDf.dropna(subset=[BULK_COL_FYYBRAND])

if not outputDf.empty:
    print("outputDf", tableize(outputDf))
else:
    print("Empty outputDf")

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

comments powered by Disqus