Script 1383: Active Ascend Strategy Campaigns Budget Floor

Purpose

The script ensures that any campaign with a daily budget below $50 is adjusted to meet this minimum threshold.

To Elaborate

The Python script is designed to manage and adjust the daily budget of marketing campaigns. Specifically, it identifies campaigns with a daily budget below $50 and updates them to ensure they meet this minimum threshold. This adjustment is crucial for maintaining a baseline level of campaign activity and ensuring that campaigns have sufficient budget to operate effectively. The script processes a dataset of campaigns, checks each campaign’s daily budget, and modifies it if necessary. The output is a list of campaigns where the budget was changed, allowing for easy tracking and verification of adjustments.

Walking Through the Code

  1. Data Preparation
    • The script begins by loading the primary data source into a DataFrame named inputDf.
    • It prints the original DataFrame for verification purposes, focusing on the campaign and daily budget columns.
  2. Budget Adjustment
    • A copy of the input DataFrame is created, named outputDf, to store the modified data.
    • The script updates the daily budget in outputDf to $50 for any campaign where the original budget is below this amount.
  3. Change Detection
    • It identifies campaigns that had their budgets changed by filtering outputDf for entries where the daily budget was set to $50.
    • A new DataFrame, changedDf, is created to store only these modified campaigns.
  4. Output and Verification
    • The script prints the updated DataFrame to verify that changes were applied correctly.
    • It checks if any changes were made and prints a message accordingly. If changes exist, it displays the final DataFrame with modified campaigns, including account, campaign, daily budget, and campaign ID.

Vitals

  • Script ID : 1383
  • Client ID / Customer ID: 1306913045 / 60268001
  • Action Type: Bulk Upload (Preview)
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Daily Budget, Campaign ID
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-09-11 17:43
  • Last Updated by dwaidhas@marinsoftware.com on 2024-09-16 20:20
> 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
59
##
## name: Active Ascend Strategy Campaigns Budget Floor
## description:
##  Looks at the Daily Budget and whenever it is below $50, the script will push a daily budget of $50
##  Outputs only the campaigns where changes were made to the budget.
## 
## author: Dana Waidhas 
## created: 2024-09-11
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_STRATEGY = 'Strategy'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_CAMPAIGN_ID = 'Campaign ID'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_DAILY_BUDGET = 'Daily Budget'
BULK_COL_CAMPAIGN_ID = 'Campaign ID'

# Print original input DataFrame for verification
print("Original input DataFrame:")
print(inputDf[[RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET]].head())

# Create a copy of the input dataframe for output
outputDf = inputDf.copy()

# Update the Daily Budget where it is below 50
outputDf[BULK_COL_DAILY_BUDGET] = outputDf[RPT_COL_DAILY_BUDGET]  # Initialize the output column with original values
outputDf.loc[outputDf[RPT_COL_DAILY_BUDGET] < 50, BULK_COL_DAILY_BUDGET] = 50  # Set budget to 50 where it is below 50

# Check if any changes were made
changed_campaigns = outputDf[outputDf[RPT_COL_DAILY_BUDGET] < 50].copy()  # Identify changed campaigns

# Create an output DataFrame that only includes campaigns that had their budgets changed
changedDf = outputDf[outputDf[BULK_COL_DAILY_BUDGET] == 50].copy()  # Only include campaigns with the updated budget

# Set the campaign ID for output
changedDf[BULK_COL_CAMPAIGN_ID] = changedDf[RPT_COL_CAMPAIGN_ID]

# Print to check if changes were applied correctly
print("\nUpdated DataFrame after setting budgets to $50 where applicable:")
print(outputDf[[RPT_COL_CAMPAIGN, RPT_COL_DAILY_BUDGET]].head())  # Show updated daily budgets

# Check if there are any changes made
if changedDf.empty:
    print("No campaigns had their daily budgets changed.")
else:
    # Display the final dataframe with only the modified campaigns
    print("\nFinal DataFrame with modified campaigns:")
    print(tableize(changedDf[[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_DAILY_BUDGET, BULK_COL_CAMPAIGN_ID]].head()))

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus