Script 131: Assign Brand or Non Brand
Purpose
The script identifies campaigns containing ‘FR’ with a blank maturity status and assigns them a ‘France’ maturity label.
To Elaborate
The Python script is designed to process a dataset of marketing campaigns, specifically identifying those campaigns that contain the string ‘FR’ in their names and have an undefined or blank maturity status. The script then assigns a ‘France’ label to the maturity status of these campaigns. This operation helps in categorizing and organizing campaigns based on their geographical focus or target market, which is crucial for marketing analysis and reporting. The script ensures that campaigns with missing maturity information are correctly labeled, facilitating better data management and decision-making.
Walking Through the Code
-
Define Constants: The script begins by defining constants for column names used in the input and output DataFrames. These constants represent the campaign and account details necessary for processing.
-
Condition Check: The script constructs a condition to filter campaigns. It checks if the ‘Campaign’ column contains the string ‘FR’ and if the ‘Campaign Maturity’ column is blank. This condition is crucial for identifying the specific campaigns that need to be updated.
-
DataFrame Filtering and Assignment: Using the condition, the script filters the input DataFrame to create an output DataFrame that includes only the relevant columns (‘Account’, ‘Campaign’, ‘Campaign Maturity’). It then assigns the value ‘France’ to the ‘Campaign Maturity’ column for the filtered campaigns.
-
Output: Finally, the script prints the modified DataFrame in a table format, showcasing the updated maturity status for the identified campaigns.
Vitals
- Script ID : 131
- Client ID / Customer ID: 1306922587 / 2
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Campaign Maturity
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-05-24 19:45
- Last Updated by Byron Porter 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
15
16
17
18
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_MATURITY = 'Campaign Maturity'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGN_MATURITY = 'Campaign Maturity'
# Check if RPT_COL_CAMPAIGN has the string 'GINSU' and RPT_COL_CAMPAIGN_MATURITY is blank
condition = (inputDf[RPT_COL_CAMPAIGN].str.contains('FR', case=True, na=False)) & (inputDf[RPT_COL_CAMPAIGN_MATURITY].isnull())
# Assign 'YahooDSP' to the 'Campaign Maturity' column in outputDf where the conditions are true
outputDf = inputDf.loc[condition, [BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_CAMPAIGN_MATURITY]]
outputDf.loc[:, BULK_COL_CAMPAIGN_MATURITY] = 'France'
# Print the tableized version of the output DataFrame
print(tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT