Script 1371: Top Kw's Clear

Purpose

The Python script clears existing dimension values to ensure only the top 20 keywords are labeled in the next day’s dimension script.

To Elaborate

The Python script is designed to manage keyword data by resetting specific dimension values in a dataset. This is done to prepare the data for a subsequent process that labels the top 20 keywords. The script takes an input DataFrame, which contains keyword-related information, and clears the values in the ‘Top Keywords’ column. This ensures that when the next day’s dimension script runs, it starts with a clean slate, allowing it to accurately label the top 20 keywords without interference from previous data. This process is crucial for maintaining the integrity and accuracy of keyword reporting and analysis, particularly in environments where keyword performance is tracked and optimized regularly.

Walking Through the Code

  1. Initialization of Constants
    • The script begins by defining several constants that represent column names used in the input and output DataFrames. These constants are used to ensure consistency and avoid hardcoding column names throughout the script.
  2. Copying and Modifying the DataFrame
    • The script creates a copy of the input DataFrame (inputDf) to a new DataFrame (outputDf). This is done to preserve the original data while making modifications to the copy.
    • It then clears the values in the ‘Top Keywords’ column of the outputDf. This step is crucial as it prepares the data for the next day’s processing by removing any existing labels, ensuring that only the top 20 keywords are labeled afresh.
  3. Output
    • Finally, the script prints the modified DataFrame (outputDf) to display the changes made, specifically showing that the ‘Top Keywords’ column has been cleared.

Vitals

  • Script ID : 1371
  • 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:12
  • 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
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_MATCH_TYPE = 'Match Type'
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()

# blank out existing dimension values so that there are only 20 keywords labeled once the next day's dimension script runs
outputDf = inputDf.copy()
outputDf[BULK_COL_TOP_KEYWORDS] = ""

print("outputDf", tableize(outputDf))

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus