Script 1701: pause inactive groups
Purpose:
The Python script pauses ad groups that have received fewer than 10 clicks in the last 60 days, provided they have been active for at least 60 days.
To Elaborate
The script is designed to manage ad group performance by identifying and pausing those that are underperforming. Specifically, it targets ad groups that have received fewer than 10 clicks over the past 60 days, ensuring that these groups have been active for at least 60 days before making any changes. This helps in optimizing ad spend by focusing resources on more effective ad groups. The script processes input data to identify such groups and updates their status to “PAUSED,” effectively halting their activity until further review or adjustment.
Walking Through the Code
-
Data Preparation: The script begins by loading data from a primary data source into a DataFrame named
inputDf
. It includes a commented-out section for adjusting the header row, which suggests that the data might require reformatting to ensure the correct headers are used. -
Column Verification: The script checks if the necessary columns (
Campaign
,Group
,Account
) are present in the DataFrame. This is crucial for ensuring that the subsequent operations can be performed without errors. -
Output DataFrame Creation: If the required columns are present, the script creates a new DataFrame,
outputDf
, which includes theAccount
,Campaign
, andGroup
columns from the input data. It sets theStatus
andGroup Status
columns to “PAUSED” for each entry, indicating that these ad groups should be paused. -
Error Handling: If the expected columns are not found in the adjusted DataFrame, the script raises a
ValueError
, alerting the user to the issue and preventing further execution.
Vitals
- Script ID : 1701
- Client ID / Customer ID: 1306926853 / 69058
- Action Type: Bulk Upload
- Item Changed: AdGroup
- Output Columns: Account, Campaign, Group, Status, Group Status
- Linked Datasource: FTP/Email Feed
- Reference Datasource: None
- Owner: Chris Jetton (cjetton@marinsoftware.com)
- Created by Chris Jetton on 2025-02-06 18:44
- Last Updated by Chris Jetton on 2025-02-07 18:10
> 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
##
## name: pause_inactive_groups
## description:
## Pause ad groups who have seen <10 clicks in the last 60 days (must have been live for 60 days)
##
## author:
## created: 2025-02-06
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
# primary data source and columns
inputDf = dataSourceDict["1"]
# Shift the header row to the correct position
#if len(inputDf) > 5: # Ensure there are at least 6 rows
#inputDf.columns = inputDf.iloc[5] # Set the 6th row as headers
#inputDf = inputDf[6:].reset_index(drop=True) # Drop previous rows and reset index
#else:
#raise ValueError("Input CSV file does not have enough rows to shift headers correctly.")
print("Headers after shifting:", inputDf.columns)
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_STATUS = 'Status'
BULK_COL_GROUP_STATUS = 'Group Status'
#outputDf[BULK_COL_STATUS] = "<<YOUR VALUE>>"
# user code start here
print(tableize(inputDf.head()))
# Check if the necessary columns exist after the adjustment
if all(col in inputDf.columns for col in [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP]):
# Output DataFrame
outputDf = pd.DataFrame({
'Account': inputDf[RPT_COL_ACCOUNT],
'Campaign': inputDf[RPT_COL_CAMPAIGN],
'Group': inputDf[RPT_COL_GROUP],
'Status': "PAUSED",
'Group Status': "PAUSED"
})
print(outputDf)
else:
raise ValueError("The expected columns are not found in the adjusted DataFrame.")
Post generated on 2025-03-11 01:25:51 GMT