Script 1675: Script Account CCC
Purpose:
The Python script processes account data to filter and transform it for structured budget allocation purposes.
To Elaborate
The script is designed to handle account data by filtering and transforming it to prepare for structured budget allocation (SBA). It specifically targets rows where the ‘Linked Date’ is not provided, indicating that these accounts need special handling. The script then creates a new dataframe with specific columns, setting default values for certain fields to ensure consistency and readiness for further processing or analysis. The primary goal is to prepare the data for SBA by ensuring that all necessary fields are populated and formatted correctly.
Walking Through the Code
- Data Initialization:
- The script begins by defining the primary data source and the relevant columns needed for processing. It initializes an empty dataframe
outputDf
with specific columns that will be used for the final output.
- The script begins by defining the primary data source and the relevant columns needed for processing. It initializes an empty dataframe
- Data Filtering:
- It filters the input data to select only those rows where the ‘Linked Date’ is missing. This step is crucial as it identifies the accounts that require special handling.
- Data Transformation:
- The filtered data is then transformed by creating a new dataframe
final_df
. It copies the ‘Account’ column and uses it to populate the ‘Campaign’ and ‘Group’ columns. The ‘Account’ column is set to a default value of ‘ZZZ Margin Account’, and a new column ‘Search Bid’ is added with a default value of $1.00.
- The filtered data is then transformed by creating a new dataframe
- Final Output Preparation:
- The columns in
final_df
are rearranged for clarity, and the transformed dataframe is assigned tooutputDf
, which will be used for further processing or output.
- The columns in
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-03-11 01:25:51 GMT