Script 803: Pacing Campaign Bulk Sheet

Purpose

Python script to filter and manipulate data from a primary data source based on specific criteria.

To Elaborate

The Python script aims to filter and manipulate data from a primary data source based on specific criteria. The script excludes campaigns that have ended and only includes campaigns with “Traffic” as the SBA Traffic value. It then applies necessary operations on the filtered data and outputs the result.

Walking Through the Code

  1. The script starts by importing the necessary libraries and defining the user changeable parameter today as the current date.
  2. It then defines the column constants for the primary data source.
  3. Next, it defines the output columns and initializes the Daily Budget column with a placeholder value.
  4. The script applies the first filter by excluding campaigns with the Campaign Ended value in the Auto. Pacing Cycle Threshold column.
  5. It applies the second filter by selecting only the campaigns where the SBA Traffic value is Traffic.
  6. The necessary operations are then applied on the filtered data. The Daily Budget column is updated with the values from the Recommended Daily Budget column, and the Pacing Calculation Date column is updated with the today value.
  7. The filtered and manipulated data is copied to the outputDf dataframe.
  8. Finally, the outputDf dataframe is printed to display or utilize the result.

Vitals

  • Script ID : 803
  • Client ID / Customer ID: 1306927731 / 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-13 15:01
  • Last Updated by ascott@marinsoftware.com on 2024-03-20 14:06
> 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
## 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

comments powered by Disqus