Script 107: Inventory Bidding 2.0

Purpose

Determines the Auction Boost amount for a group in “RBA-Pro-SEM/BSEM” campaigns.

To Elaborate

The Python script solves the problem of determining the Auction Boost amount for a group in “RBA-Pro-SEM/BSEM” campaigns. It references various data such as Pageviews conversions from GA, Dimension values populated by an inventory feed, “Inventory Bidding” status, and “IB Last Updated” to make calculations and decisions. The script applies bid boosts to groups that are opted in to boosts and have specific conditions met. It also determines the status of each group based on the value of “Kelvin Top” and pauses groups that do not meet the criteria. The script filters and prints the modified rows for further analysis.

Walking Through the Code

  1. Define column constants for easy reference.
  2. Create a new column ‘Status’ in the output dataframe and initialize it with an empty string.
  3. Check the condition for ‘Active’ status using vectorized operations on the ‘Kelvin Top’ column and update the ‘Status’ column accordingly.
  4. Check the condition for ‘Paused’ status using vectorized operations on the ‘Kelvin Top’ column and update the ‘Status’ column accordingly.
  5. Calculate the ‘AuctionBoost’ column using nested operations with priority:
    • If ‘Pageviews Conv.’ is less than 10, add 50 to the bidBoost.
    • If ‘PUP Score’ is not blank and contains either “bid up” or “bid down”, consider ‘PUP Score’ and update the bidBoost accordingly.
    • If ‘PUP Score’ is blank, consider ‘Shoot Price’ and update the bidBoost accordingly.
  6. Assign the calculated bidBoost values to the ‘AuctionBoost’ column in the output dataframe for active groups.
  7. Handle any exceptions that occur during the calculation of ‘AuctionBoost’ or checking of ‘Active’ and ‘Paused’ conditions.
  8. Filter the rows in the output dataframe that have been modified (either ‘Status’ is not empty or ‘AuctionBoost’ is not NaN).
  9. Print the modified rows in a tabular format for further analysis.

Vitals

  • Script ID : 107
  • Client ID / Customer ID: 1306913045 / 60268001
  • Action Type: Bulk Upload
  • Item Changed: AdGroup
  • Output Columns: Account, Campaign, Group, Status, AuctionBoost
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jeff Sands (jsands@marinsoftware.com)
  • Created by Jeff Sands on 2023-05-17 20:38
  • Last Updated by Jeff Sands on 2024-03-13 17:24
> 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
60
61
62
63
64
65
66
67
68
69
RPT_COL_GROUP = 'Group'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_GROUP_STATUS = 'Group Status'
RPT_COL_INVENTORY_BIDDING = 'Inventory Bidding'
RPT_COL_INVENTORY_PERCENTAGE = 'Inventory Percentage'
RPT_COL_IB_LASTUPDATED = 'IB Last Updated'
RPT_COL_PAGEVIEWS_CONV = 'Pageviews Conv.'
RPT_COL_KELVIN_TOP = 'Kelvin Top'
RPT_COL_PUP_SCORE = 'PUP Score'
RPT_COL_SHOOT_PRICE = 'Shoot Price'
RPT_COL_AUCTIONBOOST = 'AuctionBoost'
BULK_COL_STATUS = 'Status'
BULK_COL_AUCTIONBOOST = 'AuctionBoost'

# Create a new column 'Status' initialized with an empty string
outputDf[BULK_COL_STATUS] = ''

try:
    # Check condition for 'Active' status using vectorized operations
    active_condition = inputDf[RPT_COL_KELVIN_TOP].astype(float) == 1.0
    outputDf.loc[active_condition, BULK_COL_STATUS] = 'Active'

    # Check condition for 'Paused' status using vectorized operations
    paused_condition = ~active_condition
    outputDf.loc[paused_condition, BULK_COL_STATUS] = 'Paused'

    try:
        # Calculate the 'AuctionBoost' column using nested operations with priority
        bidBoost = (
            # First, consider whether Pageviews Conv. is less than 10. If yes, add 50 to bidBoost
            ((inputDf[RPT_COL_PAGEVIEWS_CONV] < 10) * 50) +
            (
                # If PUP Score is not blank and contains either "bid up" or "bid down", consider PUP Score
                (~inputDf[RPT_COL_PUP_SCORE].isna()) &
                (inputDf[RPT_COL_PUP_SCORE].astype(str).str.contains('bid up|bid down'))
            ) * (
                # If PUP Score equals "bid up", add 30 to bidBoost
                (inputDf[RPT_COL_PUP_SCORE] == 'bid up') * 30 +
                # If PUP Score equals "bid down", subtract 50 from bidBoost
                (inputDf[RPT_COL_PUP_SCORE] == 'bid down') * -50
            ) +
            (
                # If PUP Score is blank, only then should we consider Shoot Price
                (inputDf[RPT_COL_PUP_SCORE].isna()) |
                (inputDf[RPT_COL_PUP_SCORE] == '')
            ) * (
                # If Shoot Price equals "bid up", add 30 to bidBoost
                (inputDf[RPT_COL_SHOOT_PRICE] == 'bid up') * 30 +
                # If Shoot Price equals "bid down", subtract 50 from bidBoost
                (inputDf[RPT_COL_SHOOT_PRICE] == 'bid down') * -50
            )
        )
        outputDf[BULK_COL_AUCTIONBOOST] = np.where(active_condition, bidBoost, np.nan)

    except Exception as e:
        print("Error occurred while calculating 'AuctionBoost':", str(e))

except Exception as e:
    print("Error occurred while checking 'Active' and 'Paused' conditions:", str(e))


# Filter rows that have been modified
modified_rows = outputDf[outputDf[BULK_COL_STATUS].ne('') | outputDf[BULK_COL_AUCTIONBOOST].notna()]

# Print the modified rows
print(tableize(modified_rows))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus