Script 1369: Top Kw's Microsoft Brand
Purpose
The Python script identifies and labels the top-performing keywords from a sorted report based on cost per conversion.
To Elaborate
The script processes a report of advertising data to identify the top-performing keywords based on their cost per conversion. It assumes that the input data is already sorted in descending order by cost per conversion, meaning the most expensive conversions appear first. The script then selects the top ten entries from this sorted list and labels them as “Top Performer.” This helps in quickly identifying which keywords are performing best in terms of cost efficiency, allowing for more informed decision-making in advertising budget allocation.
Walking Through the Code
-
Initialization of Constants
The script begins by defining several constants that represent column names used in the report and bulk data. These constants are used to ensure consistency and readability when accessing specific columns in the dataframes. -
Date Assignment
The script assigns the current date to a variable, which is not directly used in the visible code but might be intended for timestamping or logging purposes. - Data Processing
- The script copies the first ten rows of the input dataframe (
inputDf
) into a new dataframe (outputDf
). This selection is based on the assumption that the input dataframe is pre-sorted by cost per conversion in descending order. - It then adds a new column to
outputDf
, labeling these top ten rows as “Top Performer” under the columnBULK_COL_TOP_KEYWORDS
.
- The script copies the first ten rows of the input dataframe (
- Output
Finally, the script prints the resulting dataframe, which includes the top ten keywords marked as top performers.
Vitals
- Script ID : 1369
- Client ID / Customer ID: 1306923239 / 60269197
- Action Type: Bulk Upload
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, Top Keywords
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Autumn Archibald (aarchibald@marinsoftware.com)
- Created by Autumn Archibald on 2024-09-04 22:07
- Last Updated by Autumn Archibald on 2024-09-04 22:18
> 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
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_STATUS = 'Status'
RPT_COL_TOTAL_DONATIONS = 'Total Donations (Conversions)'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_TOP_KEYWORDS = 'Top Keywords'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_TOP_KEYWORDS = 'Top Keywords'
# Assign current date to a parameter
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# Copy the first 10 rows of input dataframe to a new dataframe
# **incoming report is sorted by highest cost/conv to the lowest cost/conv**
outputDf = inputDf.head(10)
outputDf[BULK_COL_TOP_KEYWORDS] = "Top Performer"
print("outputDf", tableize(outputDf))
Post generated on 2024-11-27 06:58:46 GMT