Script 547: Keyword 1st of Month QS

Purpose

Sets Historical Quality Score - 1st of Month dimension with current QS value

To Elaborate

The Python script sets the Historical Quality Score - 1st of Month dimension with the current Quality Score value.

Walking Through the Code

  1. The script defines a dictionary called MATCH_TYPE that maps different match types to their corresponding values.
  2. The script gets the current date and assigns it to the variable today.
  3. The script defines the primary data source and column constants.
  4. The script defines the output columns and their initial values.
  5. The script creates a temporary column to store the historical quality score value.
  6. The script sets the historical quality score value by assigning the current quality score to the temporary column.
  7. The script creates a copy of the input dataframe and renames the temporary column to the desired output column.
  8. The script prints the tableized version of the input dataframe.

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-05-15 07:44:05 GMT

comments powered by Disqus