Script 1481: Script Autotag PS Clients Campaigns
Purpose
The script automatically tags PS Clients based on keywords found in campaign names.
To Elaborate
The Python script is designed to automate the process of tagging PS Clients by analyzing campaign names. It searches for specific keywords within the campaign names and assigns a corresponding client tag. This is particularly useful for organizations that need to categorize or filter campaigns based on client associations. The script ensures that each campaign is tagged with the correct client name, such as “KPMG,” “Vodafone,” or “Costa,” based on predefined keyword matches. If no match is found, it leaves the tag empty. This automation helps streamline the process of campaign management by reducing manual tagging efforts and ensuring consistency in client identification.
Walking Through the Code
- Configurable Parameters:
- The script begins by defining configurable parameters such as
SEP
for the separator used in account names andTAG_LOCATION
to specify the index position for tagging. These parameters can be adjusted by the user to fit different data structures or requirements.
- The script begins by defining configurable parameters such as
- Function Definition:
- A function
tag_psclient
is defined to determine the PS Client based on the campaign name. It checks for specific keywords like ‘kpmg’, ‘vodafone’, etc., and returns the corresponding client name. If no keyword is found, it returns an empty string.
- A function
- Data Preparation:
- The script copies all input data to an output DataFrame
outputDf
to preserve the original data. It ensures that the column for PS Client tags exists in the output DataFrame, initializing it with empty strings if necessary.
- The script copies all input data to an output DataFrame
- Applying the Function:
- The
tag_psclient
function is applied to each campaign name in the output DataFrame. This populates the PS Client column with the appropriate tags based on the campaign name.
- The
- Output Handling:
- Finally, the script checks if the output DataFrame is empty. If not, it prints the results in a tabular format; otherwise, it indicates that the output is empty.
Vitals
- Script ID : 1481
- Client ID / Customer ID: 1306927879 / 60270369
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, PS Clients
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
- Created by Grégory Pantaine on 2024-11-05 21:20
- Last Updated by Grégory Pantaine on 2024-11-05 21:30
> 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
##
## Name: Auto tagging PS Clients Dimension
## Description: Return PS Clients 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_PSCLIENTDIM = 'PS Clients'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_PSCLIENTDIM = 'PS Clients'
# Define a function to tag the PS client
def tag_psclient(campaign_name):
# Specific location-based conditions
if 'kpmg' in campaign_name.lower():
return "KPMG"
elif 'stcec' in campaign_name.lower():
return "KPMG"
elif 'icaew' in campaign_name.lower():
return "ICAEW"
elif 'vodafone' in campaign_name.lower():
return "Vodafone"
elif 'vf' in campaign_name.lower():
return "Vodafone"
elif 'unlocked' in campaign_name.lower():
return "Unlocked"
elif 'costa' in campaign_name.lower():
return "Costa"
elif 'wliot' in campaign_name.lower():
return "Wliot"
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_PSCLIENTDIM not in outputDf.columns:
outputDf[BULK_COL_PSCLIENTDIM] = ""
# Apply the tag_psclient function to each row in the outputDf DataFrame
outputDf[BULK_COL_PSCLIENTDIM] = outputDf[BULK_COL_CAMPAIGN].apply(tag_psclient)
# Print results if not empty
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