Script 1675: Script Account CCC

Purpose

The Python script processes account data to filter and transform it for structured budget allocation (SBA) purposes.

To Elaborate

The Python script is designed to process account data by filtering and transforming it to meet specific business requirements related to structured budget allocation (SBA). It takes an input data frame containing account information and filters out rows where the ‘Linked Date’ is not specified. The script then creates a new data frame with selected columns, modifying the account information to a predefined value and setting a default search bid amount. This transformation is aimed at preparing the data for further processing or analysis, ensuring that only relevant and correctly formatted data is used in subsequent steps.

Walking Through the Code

  1. Data Initialization
    The script begins by defining the primary data source and necessary column names. It initializes an empty output data frame with specific columns required for further processing.

  2. Data Filtering
    The script filters the input data frame to retain only those rows where the ‘Linked Date’ is blank (NaN). This step ensures that only unlinked accounts are processed.

  3. Data Transformation
    A new data frame is created from the filtered data, copying the ‘Account’ column and using it to populate the ‘Campaign’ and ‘Group’ columns. The ‘Account’ column is then set to a fixed value, ‘ZZZ Margin Account’, and a new column, ‘Search Bid’, is added with a default value of $1.00.

  4. Final Data Preparation
    The columns in the final data frame are rearranged for clarity, and this transformed data frame is assigned to the output data frame for further use.

Vitals

  • Script ID : 1675
  • Client ID / Customer ID: 1306928641 / 60270613
  • Action Type: Bulk Upload (Preview)
  • Item Changed: AdGroup
  • Output Columns: Account, Campaign, Group, Search Bid
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Jesus Garza (jgarza@marinsoftware.com)
  • Created by Jesus Garza on 2025-01-28 17:17
  • Last Updated by Jesus Garza on 2025-02-10 17:51
> 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
##
## name: Script - Account CCC
## description:
##  
## 
## author: 
## created: 2025-01-28
## 

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

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_ACCOUNT = 'Account'
RPT_COL_DATE = 'Date'
RPT_COL_PUBLISHER = 'Publisher'
RPT_COL_ACCOUNT_PUB_ID = 'Account Pub. ID'
RPT_COL_LINKED_DATE = 'Linked Date'

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_GROUP = 'Group'
BULK_COL_SEARCH_BID = 'Search Bid'

# Initialize `outputDf` with the necessary columns
outputDf = pd.DataFrame(columns=[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_GROUP, BULK_COL_SEARCH_BID])

# Filter rows where 'Linked Date' is blank (NaN)
filtered_df = inputDf[inputDf[RPT_COL_LINKED_DATE].isna()]

# Create the final dataframe with required columns and modifications
final_df = filtered_df[[RPT_COL_ACCOUNT]].copy()
final_df[BULK_COL_CAMPAIGN] = final_df[RPT_COL_ACCOUNT]
final_df[BULK_COL_GROUP] = final_df[RPT_COL_ACCOUNT]
final_df[BULK_COL_ACCOUNT] = 'ZZZ Margin Account'
final_df[BULK_COL_SEARCH_BID] = 1.00  # Add the 'Search Bid' column set to $1.00

# Rearrange columns for clarity
final_df = final_df[[BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_GROUP, BULK_COL_SEARCH_BID]]

# Assign the final dataframe to `outputDf`
outputDf = final_df.copy()

# Print the input dataframe for inspection
print(tableize(inputDf.head()))

Post generated on 2025-02-21 10:25:25 GMT

comments powered by Disqus