Script 1471: Script Dimension AutoTag Campaigns Manufacturer
Purpose
The script automatically tags manufacturer names based on keywords found in campaign names.
To Elaborate
The Python script is designed to automate the process of tagging manufacturer names by analyzing the campaign names within a dataset. It identifies specific keywords associated with different manufacturers and assigns the corresponding manufacturer name to each campaign. This is particularly useful for businesses that need to categorize or filter campaigns by manufacturer for reporting or analysis purposes. The script processes each campaign name, checks for the presence of predefined keywords, and assigns a manufacturer tag accordingly. If no keywords are found, it leaves the manufacturer field blank. This automation helps streamline data management and ensures consistency in manufacturer tagging across large datasets.
Walking Through the Code
- Configuration and Setup:
- The script begins by defining configurable parameters such as
SEP
for separators in account names andTAG_LOCATION
to specify the position of the tag. - It initializes the input DataFrame
inputDf
from a data source dictionary.
- The script begins by defining configurable parameters such as
- Function Definition:
- A function
tag_manufacturer
is defined to determine the manufacturer based on keywords in the campaign name. It checks for specific keywords like ‘honda’, ‘kawasaki’, etc., and returns the corresponding manufacturer name.
- A function
- Data Processing:
- The script copies the input DataFrame to
outputDf
to preserve the original data. - It ensures the manufacturer column exists in
outputDf
and initializes it if necessary.
- The script copies the input DataFrame to
- Application of Tagging:
- The
tag_manufacturer
function is applied to each campaign name in theoutputDf
DataFrame, populating the manufacturer column with the appropriate tags.
- The
- Output Handling:
- The script checks if the
outputDf
is empty and prints the tableized DataFrame if it contains data, ensuring visibility of the processed results.
- The script checks if the
Vitals
- Script ID : 1471
- Client ID / Customer ID: 1306928469 / 60270543
- Action Type: Bulk Upload
- Item Changed: Campaign
- Output Columns: Account, Campaign, Manufacturer
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
- Created by Grégory Pantaine on 2024-10-31 17:34
- Last Updated by emerryfield@marinsoftware.com on 2024-11-09 00:13
> 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
51
52
53
54
55
56
57
58
59
60
61
62
63
##
## Name: Auto tagging Manufacturer Dimension
## Description: Return Manufacturer Name Based on what's in campaign name.
##
## author: Gregory Pantaine
## created: 2024-10-31
## Configurable Params - START
SEP = '_' # Separator used in account names (if applicable)
TAG_LOCATION = 1 # Comes after the first separator (0-based index)
inputDf = dataSourceDict["1"]
# Output columns and initial values
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_MANUF = 'Manufacturer'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_MANUF = 'Manufacturer'
# Define a function to tag the manufacturer
def tag_manufacturer(campaign_name):
if 'honda' in campaign_name.lower():
return "Honda"
elif 'kawasaki' in campaign_name.lower():
return "Kawasaki"
elif 'polaris' in campaign_name.lower():
return "Polaris"
elif 'suzuki' in campaign_name.lower():
return "Suzuki"
elif 'ski-doo' in campaign_name.lower():
return "Ski-Doo"
elif 'sea-doo' in campaign_name.lower():
return "Sea-Doo"
elif 'artic cat' in campaign_name.lower():
return "Artic Cat"
elif 'canam' in campaign_name.lower():
return "CanAM"
elif 'can-am' in campaign_name.lower():
return "CanAM"
elif 'aftermarket' in campaign_name.lower():
return "Aftermarket"
elif 'yamaha' in campaign_name.lower():
return "Yamaha"
else:
return "" # Return an empty string if no match is found
# Copy all input rows to output
outputDf = inputDf.copy()
# Ensure the output column exists before assigning
if BULK_COL_MANUF not in outputDf.columns:
outputDf[BULK_COL_MANUF] = ""
# Apply the tag_manufacturer function to each row in the outputDf DataFrame
outputDf[BULK_COL_MANUF] = outputDf[BULK_COL_CAMPAIGN].apply(tag_manufacturer)
if not outputDf.empty:
print("outputDf", tableize(outputDf))
else:
print("Empty outputDf")
# Configurable Params - END
Post generated on 2024-11-27 06:58:46 GMT