Script 759: Script 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. The key business rules are as follows:
- Exclude campaigns that have ended.
- Include only campaigns with SBA Traffic as ‘Traffic’.
- Update the Daily Budget and Pacing Calculation Date columns of the filtered campaigns.
- Display or utilize the resulting output data.
Walking Through the Code
- The script starts by importing the necessary libraries and defining the required constants.
- The primary data source and column constants are defined.
- The output columns and initial values are set.
- The first filter is applied to exclude campaigns that have ended.
- The second filter is applied to include only campaigns with SBA Traffic as ‘Traffic’.
- Necessary operations are performed on the filtered data, updating the Daily Budget and Pacing Calculation Date columns.
- The resulting output data is stored in the outputDf variable.
- The output data is printed or can be utilized further.
Vitals
- Script ID : 759
- Client ID / Customer ID: 1306927181 / 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 21:39
- Last Updated by ascott@marinsoftware.com on 2024-04-05 19:55
> 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