Script 547: Keyword 1st of Month QS
Purpose
The script updates a historical quality score dimension with the current quality score value for the first of the month.
To Elaborate
The Python script is designed to update a specific dimension called “Historical Quality Score - 1st of the Month” with the current quality score value from a dataset. This operation is typically performed on the first day of each month to capture the quality score at that point in time. The script processes data related to keywords, accounts, campaigns, groups, and match types, ensuring that the historical quality score reflects the current state of these metrics. The primary goal is to maintain a record of quality scores that can be used for historical analysis and performance tracking over time.
Walking Through the Code
- Initialization and Setup
- The script begins by defining a dictionary
MATCH_TYPE
to map match types to their respective string representations. - It retrieves the current date using the
datetime
module, although this part is not directly relevant to the main functionality described.
- The script begins by defining a dictionary
- Data Source and Column Definitions
- The script accesses a primary data source,
inputDf
, which contains columns such as ‘Keyword’, ‘Account’, ‘Campaign’, ‘Group’, ‘Match Type’, ‘Status’, and ‘Quality Score’. - It also defines output columns, including ‘Historical Quality Score - 1st of the month’, which will store the updated quality score.
- The script accesses a primary data source,
- Processing Quality Scores
- A temporary column,
TMP_QUALITY_SCORE
, is created to hold the current quality score values. - The script assigns the current quality score from the input data to this temporary column.
- A temporary column,
- Output DataFrame Creation
- The script copies the input DataFrame to a new DataFrame,
outputDf
, and renames the temporary quality score column to ‘Historical Quality Score - 1st of the month’. - This step finalizes the update of the historical quality score dimension with the current values.
- The script copies the input DataFrame to a new DataFrame,
- Output Display
- The script concludes by printing the input DataFrame using a function
tableize
, which is assumed to format the data for display purposes.
- The script concludes by printing the input DataFrame using a function
Vitals
- Script ID : 547
- Client ID / Customer ID: 1306926109 / 60269815
- Action Type: Bulk Upload
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, Historical Quality Score - 1st of the month
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-11-29 15:20
- 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
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
##
## name: Keyword - 1st of Month QS
## description:
## Sets Historical Quality Score - 1st of Month dimension with current QS value
##
## author:
## created: 2023-11-29
##
MATCH_TYPE = {
'EXACT': 'exact',
'PHRASE': 'phrase',
'BROAD': 'broad',
}
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
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_QUALITY_SCORE = 'Quality Score'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_HISTORICAL_QUALITY_SCORE__1ST_OF_THE_MONTH = 'Historical Quality Score - 1st of the month'
# temp column to set historical quality score value
TMP_QUALITY_SCORE = RPT_COL_QUALITY_SCORE + '_'
inputDf[TMP_QUALITY_SCORE] = np.nan
# set dimension value
inputDf[TMP_QUALITY_SCORE] = inputDf[RPT_COL_QUALITY_SCORE]
# copy input dataframe to output
outputDf = inputDf.copy() \
.rename(columns = { \
TMP_QUALITY_SCORE: BULK_COL_HISTORICAL_QUALITY_SCORE__1ST_OF_THE_MONTH, \
})
# user code start here
print(tableize(inputDf))
Post generated on 2024-11-27 06:58:46 GMT