Script 1431: Current OAP Dimension Tagging

Purpose

The script tags the “Current Organic Average Position” dimension with the previous day’s data from Google Search Console.

To Elaborate

The Python script is designed to update a dataset by tagging the “Current Organic Average Position” dimension with data from the previous day, sourced from Google Search Console. This process involves taking the “Organic Average Position” from the input data, converting it to a numeric format, and handling any missing values by replacing them with zero. The script ensures that the data is prepared for further analysis or reporting by maintaining consistency in the data type and structure. This operation is crucial for businesses that rely on accurate and up-to-date search performance metrics to make informed decisions about their online presence and marketing strategies.

Walking Through the Code

  1. Initialization and Setup
    • The script begins by defining a dictionary MATCH_TYPE to map different match types to their string representations.
    • It retrieves the primary data source into inputDf from a dictionary dataSourceDict using a specific key.
  2. Data Preparation
    • The script initializes outputDf as a copy of inputDf to preserve the original data while making modifications.
    • It coerces the “Organic Average Position” column to a float type, filling any missing values with zero to ensure data integrity.
  3. Data Conversion
    • The script converts the “Current Organic Average Position” to a float type, ensuring that all positions are consistently formatted for further processing or analysis.
  4. Output
    • Finally, the script prints the modified DataFrame outputDf to display the updated data, and it also prints a table representation of the first few rows of the input data for verification purposes.

Vitals

  • Script ID : 1431
  • Client ID / Customer ID: 1306928241 / 60269279
  • Action Type: Bulk Upload
  • Item Changed: Keyword
  • Output Columns: Account, Campaign, Group, Keyword, Match Type, Current Organic Average Position
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jeff Sands (jsands@marinsoftware.com)
  • Created by Jeff Sands on 2024-10-10 15:22
  • Last Updated by Jeff Sands on 2024-10-10 15:43
> 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
##
## name: Current OAP Dimension Tagging
## description:
##  Tag "Current Organic Average Position" dimension with yesterday's
##  Organic Average Position from Google search console data.
## author: Jeff Sands
## created: 2024-10-10
## 

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_STATUS = 'Status'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_ORGANIC_AVERAGE_POSITION_CONV = 'Organic Average Position Conv.'
RPT_COL_CURRENT_ORGANIC_AVERAGE_POSITION = 'Current Organic Average Position'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CURRENT_ORGANIC_AVERAGE_POSITION = 'Current Organic Average Position'

# Output DataFrame initialization
outputDf = inputDf.copy()

# Coerce the Organic Average Position to a float type explicitly, filling NaNs with a placeholder if needed
outputDf[RPT_COL_CURRENT_ORGANIC_AVERAGE_POSITION] = pd.to_numeric(
    inputDf[RPT_COL_ORGANIC_AVERAGE_POSITION_CONV], errors='coerce'
).fillna(0)  # Fill missing values with 0

# Convert to integer if you expect all positions to be integers
outputDf[RPT_COL_CURRENT_ORGANIC_AVERAGE_POSITION] = outputDf[RPT_COL_CURRENT_ORGANIC_AVERAGE_POSITION].astype(float)

# Display the result
print(outputDf)
# user code start here
print(tableize(inputDf.head()))

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

comments powered by Disqus