Script 631: Alert CCT Groups paused (Single word keywords)

Purpose

The Python script identifies paused CCT groups with single-word keywords that have been paused within the last five days.

To Elaborate

The script processes a dataset to identify specific paused CCT (Cost-per-Click Tracking) groups that contain single-word keywords. It focuses on extracting and analyzing the pause date and reason from a particular column in the dataset. The script then filters these entries to find those that have been paused within the last five days. This helps in monitoring and managing keyword performance by quickly identifying recent changes in keyword status, allowing for timely interventions or adjustments in marketing strategies.

Walking Through the Code

  1. Data Preparation
    • The script begins by defining a dictionary MATCH_TYPE to categorize keywords by their match type (exact, phrase, broad).
    • It retrieves the primary data source into inputDf, which contains various columns related to keyword performance and status.
  2. Data Extraction and Transformation
    • The script extracts the ‘Pause Date’ and ‘Pause Reason’ from the CCT_Single_keyword_processing column by splitting the string data.
    • It converts the extracted ‘Pause Date’ strings into datetime objects for accurate date manipulation and comparison.
  3. Date Calculation and Filtering
    • It calculates the date five days prior to the current date.
    • The script filters the DataFrame to include only those entries where the ‘Pause Date’ is within the last five days, storing the result in filtered_df.
  4. Output Preparation
    • The filtered DataFrame, filtered_df, is assigned to outputDf, which can be used for further analysis or reporting.

Vitals

  • Script ID : 631
  • Client ID / Customer ID: 1306924347 / 69058
  • Action Type: Email Report
  • Item Changed: None
  • Output Columns:
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jonathan Reichl (jreichl@marinsoftware.com)
  • Created by Jonathan Reichl on 2023-12-22 16:17
  • Last Updated by Jonathan Reichl on 2023-12-22 16:17
> 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
52
53
54
55
56
57
58
59
##
## name: Alert paused cct single keywords
## description:
##  
## 
## author: 
## created: 2023-12-19
## 

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_PUBLISHER = 'Publisher'
RPT_COL_CCT_SOURCETEMPLATE = 'CCT_sourcetemplate'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_STATUS = 'Status'
RPT_COL_KEYWORD_ID = 'Keyword ID'
RPT_COL_PUB_ID = 'Pub. ID'
RPT_COL_CCT_SINGLE_KEYWORD_PROCESSING = 'CCT_Single_keyword_processing'

# output columns and initial values

# user code start here
print(tableize(inputDf))




# Splitting and extracting date
inputDf['Pause Date'] = inputDf[RPT_COL_CCT_SINGLE_KEYWORD_PROCESSING].str.split('|').str[2]

inputDf['Pause Reason'] = inputDf[RPT_COL_CCT_SINGLE_KEYWORD_PROCESSING].str.split('|').str[1]


# Convert strings to datetime objects
inputDf['Pause Date'] = pd.to_datetime(inputDf['Pause Date'])


# Calculating 5 days ago from today
five_days_ago = today - datetime.timedelta(days=5)

# Convert the 'five_days_ago' date object to a pandas Timestamp for comparison
five_days_ago = pd.Timestamp(five_days_ago)



# Filtering the DataFrame
filtered_df = inputDf[inputDf['Pause Date'] >= five_days_ago]

outputDf = filtered_df

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

comments powered by Disqus