Script 45: Daily Clear Labels
Purpose
Clear Daily Winner and Overspend labels daily
To Elaborate
The Python script clears the Daily Winner and Overspend labels on a daily basis. It identifies any changes in the labels and outputs the updated labels in a specific format.
Walking Through the Code
- The script defines column constants for various columns used in the code.
- It creates temporary column names for the Daily Winner and Overspend labels.
- It adds the temporary columns to the input dataframe and fills any missing values with an empty string.
- It checks for changes in the Daily Winner and Overspend labels by comparing the original columns with the temporary columns.
- It prints the number of changes detected.
- It creates an output dataframe by selecting the relevant columns from the input dataframe where changes were detected.
- It renames the temporary columns to the desired column names for the output dataframe.
- It prints the output dataframe in a specific format.
Vitals
- Script ID : 45
- Client ID / Customer ID: 1306925293 / 60269377
- Action Type: Bulk Upload
- Item Changed: AdGroup
- Output Columns: Account, Campaign, Group, Daily Winner, Daily (Overspent)
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Michael Huang (mhuang@marinsoftware.com)
- Created by Michael Huang on 2023-04-10 12:08
- Last Updated by Michael Huang 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
RPT_COL_GROUP = 'Group'
RPT_COL_DAILY_WINNER = 'Daily Winner'
RPT_COL_DAILY_OVERSPENT = 'Daily (Overspent)'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_DAILY_OVERSPENT = 'Daily (Overspent)'
BULK_COL_DAILY_WINNER = 'Daily Winner'
winner_tmp = RPT_COL_DAILY_WINNER + "_"
overspend_tmp = RPT_COL_DAILY_OVERSPENT + "_"
inputDf[winner_tmp] = np.nan
inputDf[overspend_tmp] = np.nan
inputDf.fillna('', inplace=True)
changed = ( (inputDf[RPT_COL_DAILY_WINNER] != inputDf[winner_tmp]) | \
(inputDf[RPT_COL_DAILY_OVERSPENT] != inputDf[overspend_tmp]) \
)
print("changed: ", sum(changed))
outputDf = inputDf.loc[changed, [RPT_COL_ACCOUNT, RPT_COL_CAMPAIGN, RPT_COL_GROUP, winner_tmp, overspend_tmp]].copy()
outputDf.rename(columns={
winner_tmp: BULK_COL_DAILY_WINNER, \
overspend_tmp: BULK_COL_DAILY_OVERSPENT}, \
inplace=True)
print(outputDf.to_string())
Post generated on 2024-05-15 07:44:05 GMT