Script 269: script good performing keyword 2
Purpose
Python script for adjusting bids based on certain conditions.
To Elaborate
This Python script adjusts bids for keywords based on specific conditions. The script takes input data and applies bid adjustments to certain keywords based on their performance metrics. The bid adjustments are determined by a set of rules and conditions. The adjusted bids are then outputted as a new column in the output data.
Walking Through the Code
- Define column constants for input and output data.
- Create new columns in the output data for bid adjustments.
- Get the current date and time.
- Print the input data in a table format.
- Define temporary fields for bid adjustments.
- Define conditions for bid adjustments based on campaign types.
- Apply bid adjustments to the input data based on the defined conditions.
- Set bid override values for keywords that meet the conditions.
- Calculate the adjusted bids based on the bid override values and other metrics.
- Add the adjusted bids to the output data.
- Filter the output data to include only keywords with adjusted bids.
- Output the final output data.
Vitals
- Script ID : 269
- Client ID / Customer ID: 1306912115 / 69058
- Action Type: Bulk Upload (Preview)
- Item Changed: Keyword
- Output Columns: Account, Campaign, Group, Keyword, Match Type, Bid Override, Search Bid
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Jonathan Reichl (jreichl@marinsoftware.com)
- Created by Jonathan Reichl on 2023-08-03 09:51
- Last Updated by Jonathan Reichl on 2023-12-06 04:01
> 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
70
71
72
73
74
75
76
77
78
RPT_COL_KEYWORD = 'Keyword'
RPT_COL_CAMPAIGN_LANGUAGE = 'Campaign Language'
RPT_COL_MATCH_TYPE = 'Match Type'
RPT_COL_TITLE = 'Title'
RPT_COL_GROUP = 'Group'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_GROUP_STATUS = 'Group Status'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_IMPR = 'Impr.'
RPT_COL_CONV = 'Conv.'
RPT_COL_COST_PER_CONV = 'Cost/Conv. $'
RPT_COL_IMPR_SHARE = 'Impr. share %'
RPT_COL_SEARCH_BID = 'Search Bid'
RPT_COL_MIN_BID = 'Min Bid $'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_KEYWORD = 'Keyword'
BULK_COL_MATCH_TYPE = 'Match Type'
BULK_COL_SEARCH_BID = 'Search Bid'
BULK_COL_BID_OVERRIDE = 'Bid Override'
RPT_COL_BID_OVERRIDE = 'Bid Override'
outputDf[BULK_COL_SEARCH_BID] = "<<YOUR VALUE>>"
outputDf[BULK_COL_BID_OVERRIDE] = "<<YOUR VALUE>>"
today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))
UPDATE_BID = RPT_COL_SEARCH_BID + '_new'
UPDATE_BID_OV = BULK_COL_BID_OVERRIDE + '_new'
# blank out tmp field
inputDf[UPDATE_BID] = np.nan
inputDf[UPDATE_BID_OV] = np.nan
# Conditions for bid adjustments
brand_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Brand', case=False)
generic_competitor_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Generic|Competitor', case=False) & ~brand_condition
title_condition = inputDf[RPT_COL_CAMPAIGN].str.contains('Title', case=False) & ~brand_condition & ~generic_competitor_condition
# Apply bid adjustments
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.15
inputDf.loc[brand_condition & (inputDf[RPT_COL_CONV] > 20) & (inputDf[RPT_COL_COST_PER_CONV] < 10) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.10
inputDf.loc[generic_competitor_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] <= 100), UPDATE_BID_OV] = 'On'
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] < 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]*1.15
inputDf.loc[title_condition & (inputDf[RPT_COL_CONV] > 10) & (inputDf[RPT_COL_COST_PER_CONV] < 15) & (inputDf[RPT_COL_IMPR_SHARE] == 100), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf.loc[(inputDf[UPDATE_BID_OV] != 'On'), UPDATE_BID_OV] = 'Off'
inputDf.loc[(inputDf[UPDATE_BID_OV] != 'On'), UPDATE_BID] = inputDf[RPT_COL_SEARCH_BID]
inputDf[UPDATE_BID] = inputDf.apply(
lambda row: max(row[UPDATE_BID], row[RPT_COL_MIN_BID]) if row[UPDATE_BID_OV] == 'On' else row[UPDATE_BID],
axis=1
)
#add new values to outputDf
outputDf.loc[:,BULK_COL_SEARCH_BID] = inputDf.loc[:, UPDATE_BID]
outputDf.loc[:,BULK_COL_BID_OVERRIDE] = inputDf.loc[:, UPDATE_BID_OV]
outputDf = outputDf[
(inputDf[UPDATE_BID].notnull()) &
((inputDf[UPDATE_BID_OV] == 'On') | (inputDf[UPDATE_BID_OV] != inputDf[RPT_COL_BID_OVERRIDE]))
]
Post generated on 2024-05-15 07:44:05 GMT