Script 733: Avg CPC Benchmark

Purpose

The Python script calculates and stores the average cost-per-click (CPC) for the last 28 days in a dimension called “Test.”

To Elaborate

The Python script is designed to process advertising data by extracting and storing the average cost-per-click (CPC) for the last 28 days into a specific dimension named “Test.” This is achieved by reading data from a primary data source, checking for the presence of the “Avg. CPC $” column, and then transferring this data into a structured output format. The script ensures that the relevant columns, such as “Account” and “Campaign,” are preserved and transferred to the output data frame. If the “Avg. CPC $” column is not found, the script handles this by setting the “Test” column to None, ensuring robustness in data processing.

Walking Through the Code

  1. Data Initialization
    • The script begins by defining the primary data source, inputDf, which contains the advertising data.
    • It initializes an empty DataFrame, outputDf, with columns for “Account,” “Campaign,” and “Test.”
  2. Data Transfer and Validation
    • The script copies the “Account” and “Campaign” columns from inputDf to outputDf.
    • It checks if the “Avg. CPC $” column exists in inputDf. If it does, the values are copied to the “Test” column in outputDf. If not, the “Test” column is set to None, and a message is printed to indicate the missing column.
  3. Output Display
    • Finally, the script prints the outputDf to display the structured data with the average CPC values.

Vitals

  • Script ID : 733
  • Client ID / Customer ID: 6968245 / 3374365
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Test
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: wmaclaggan@marinsoftware.com (wmaclaggan@marinsoftware.com)
  • Created by wmaclaggan@marinsoftware.com on 2024-03-01 23:11
  • Last Updated by wmaclaggan@marinsoftware.com on 2024-03-01 23: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
##
## name: WJM Test
## description:
##  
## 
## author: 
## created: 2024-03-01
## 

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

# primary data source and columns
inputDf = dataSourceDict["1"]
print(tableize(inputDf))

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_TEST = 'Test'

# Initialize outputDf with the required columns
outputDf = pd.DataFrame(columns=[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_TEST])

# Assuming 'Account' and 'Campaign' are columns in inputDf, copy them to outputDf
outputDf[BULK_COL_ACCOUNT] = inputDf['Account']
outputDf[BULK_COL_CAMPAIGN] = inputDf['Campaign']

# Check if 'Avg. CPC' column exists in inputDf and copy it to 'Test' in outputDf
if 'Avg. CPC $' in inputDf.columns:
    outputDf[BULK_COL_TEST] = inputDf['Avg. CPC $']
else:
    print("'Avg. CPC' column not found in inputDf")
    outputDf[BULK_COL_TEST] = None

# user code start here
print(tableize(outputDf))



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

comments powered by Disqus