Script 983: New Vehicle Low Inventory Auto Pausing
Purpose
Python script to pause ad groups in select model-based new vehicle campaigns if there are 3 or fewer vehicles in stock.
To Elaborate
The Python script aims to automate the process of pausing ad groups in specific model-based new vehicle campaigns when the number of vehicles in stock is 3 or fewer. This helps optimize advertising spend by preventing ads from running when there is limited inventory available. The script takes input data from a primary data source and updates the status of ad groups based on the “Model Count” column. If the “Model Count” is less than or equal to 3, the script sets the status of the ad group to “Paused”. The output is a dataframe containing the account, campaign, group, and status columns for the paused ad groups.
Walking Through the Code
- The script starts by importing the necessary libraries and defining the user changeable parameter
today
as the current date. - It then defines the primary data source and the column constants used in the script.
- The output dataframe is initialized with the required columns and default values.
- The script updates the status column in the output dataframe based on the “Model Count” column in the input dataframe. If the “Model Count” is less than or equal to 3, the status is set to “Paused”.
- Finally, the script filters the output dataframe to include only the rows where the status is “Paused” and prints the resulting table.
Vitals
- Script ID : 983
- Client ID / Customer ID: 1306926957 / 60270165
- Action Type: Bulk Upload
- Item Changed: AdGroup
- Output Columns: Account, Campaign, Group, Status
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jeff Sands (jsands@marinsoftware.com)
- Created by Jeff Sands on 2024-04-17 15:11
- Last Updated by Jeff Sands on 2024-04-17 15:12
> 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
##
## name: New Vehicle Low Inventory Auto-Pausing
## description:
## Pause ad groups in select model-based new vehicle campaigns if there are 3 or fewer vehicles in stock.
##
## author:
## created: 2024-04-17
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_GROUP_STATUS = 'Group Status'
RPT_COL_CCT_SOURCETEMPLATE = 'CCT_sourcetemplate'
RPT_COL_MODEL_COUNT = 'Model Count'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_STATUS = 'Status'
outputDf = pd.DataFrame(columns=[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_GROUP, BULK_COL_STATUS])
# Set initial values for outputDf based on inputDf
outputDf[BULK_COL_ACCOUNT] = inputDf[RPT_COL_ACCOUNT]
outputDf[BULK_COL_CAMPAIGN] = inputDf[RPT_COL_CAMPAIGN]
outputDf[BULK_COL_GROUP] = inputDf[RPT_COL_GROUP]
outputDf[BULK_COL_STATUS] = "Active" # Default status
# Update the status based on the "Model Count" being less than or equal to 3
outputDf.loc[inputDf[RPT_COL_MODEL_COUNT] <= 3, BULK_COL_STATUS] = "Paused"
# Filter to output only rows where status is "Paused"
outputDf = outputDf[outputDf[BULK_COL_STATUS] == "Paused"]
print(tableize(outputDf))
Post generated on 2024-05-15 07:44:05 GMT