Script 767: Pacing Campaign Bulk Sheet
Purpose
Python script to filter and process campaign data based on specific criteria.
To Elaborate
The Python script filters campaign data based on certain criteria and performs necessary operations on the filtered data. It aims to identify campaigns that have not ended and have a specific type of traffic. The script then applies certain calculations and updates the daily budget and pacing calculation date for these campaigns. The output is a modified dataframe containing the filtered and processed campaign data.
Walking Through the Code
- The script starts by importing the necessary libraries and defining the required constants.
- It retrieves the primary data source and assigns it to the variable
inputDf
. - The script defines the column names used in the data processing.
- It creates a new column in the output dataframe
outputDf
for the daily budget and assigns a placeholder value. - The script applies the first filter by excluding campaigns that have the status ‘Campaign Ended’ using the column
RPT_COL_AUTO_PACING_CYCLE_THRESHOLD
. - It applies the second filter by selecting campaigns where the SBA Traffic is ‘Traffic’ using the column
RPT_COL_SBA_TRAFFIC
. - The script performs necessary operations on the filtered dataframe
filteredDf
by updating the daily budget and pacing calculation date columns. - The modified dataframe
outputDf
is created by copying the filtered dataframe. - The script prints the output dataframe
outputDf
, assuming it is intended for display or further utilization.
Vitals
- Script ID : 767
- Client ID / Customer ID: 1306927185 / 60270139
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Daily Budget, Pacing Calculation Date
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: ascott@marinsoftware.com (ascott@marinsoftware.com)
- Created by ascott@marinsoftware.com on 2024-03-06 22:00
- Last Updated by ascott@marinsoftware.com on 2024-03-19 18:44
> 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
##
## name: Campaign Bulk Sheet
## description:
##
##
## author:
## created: 2024-03-04
##
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_DATE = 'Date'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_AUTO_PACING_CYCLE_START_DATE = 'Auto. Pacing Cycle Start Date'
RPT_COL_AUTO_PACING_CYCLE_END_DATE = 'Auto. Pacing Cycle End Date'
RPT_COL_AUTO_PACING_CYCLE_DAYS_ELAPSED = 'Auto. Pacing Cycle Days Elapsed'
RPT_COL_AUTO_PACING_CYCLE_DAYS_REMAINING = 'Auto. Pacing Cycle Days Remaining'
RPT_COL_AUTO_PACING_CYCLE_PACING = 'Auto. Pacing Cycle Pacing'
RPT_COL_AUTO_PACING_CYCLE_THRESHOLD = 'Auto. Pacing Cycle Threshold'
RPT_COL_TOTAL_TARGET_SPEND_PER_IMPRVIEWS = 'Total Target (Spend/Impr./Views)'
RPT_COL_TOTAL_DAYS = 'Total Days'
RPT_COL_TOTAL_DAYS_ELAPSED = 'Total Days Elapsed'
RPT_COL_TOTAL_PACING = 'Total Pacing'
RPT_COL_DELIVERY_STATUS = 'Delivery Status'
RPT_COL_RECOMMENDED_DAILY_BUDGET = 'Recommended Daily Budget'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PACING_CALCULATION_DATE = 'Pacing Calculation Date'
RPT_COL_SOCIAL_BUDGET = 'Social Budget'
RPT_COL_SOCIAL_BUDGET_UPDATE_STATUS = 'Social Budget Update Status'
RPT_COL_AUTO_PACING_CYCLE_PUB_COST = 'Auto. Pacing Cycle Pub. Cost'
RPT_COL_AUTO_PACING_CYCLE_IMPR = 'Auto. Pacing Cycle Impr.'
RPT_COL_AUTO_PACING_CYCLE_CLICKS = 'Auto. Pacing Cycle Clicks'
RPT_COL_AUTO_PACING_CYCLE_VIEWS = 'Auto. Pacing Cycle Views'
RPT_COL_SBA_TRAFFIC = 'SBA Traffic'
# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
outputDf[BULK_COL_DAILY_BUDGET] = "<<YOUR VALUE>>"
# First filter: Exclude campaigns with 'Campaign Ended'
campaigns_not_ended = inputDf[inputDf[RPT_COL_AUTO_PACING_CYCLE_THRESHOLD] != 'Campaign Ended']
# Second filter: From the remaining, only include those where SBA Traffic is 'Traffic'
filteredDf = campaigns_not_ended[campaigns_not_ended[RPT_COL_SBA_TRAFFIC] == 'Traffic']
# Apply necessary operations on filteredDf
filteredDf.loc[:, RPT_COL_DAILY_BUDGET] = filteredDf[RPT_COL_RECOMMENDED_DAILY_BUDGET]
filteredDf.loc[:, RPT_COL_PACING_CALCULATION_DATE] = today
outputDf = filteredDf.copy()
# Assuming you want to display or utilize outputDf
print(outputDf)
Post generated on 2024-05-15 07:44:05 GMT