Script 131: Assign Brand or Non Brand
Purpose
Assign ‘YahooDSP’ to the ‘Campaign Maturity’ column in the output DataFrame where the conditions are true.
To Elaborate
The Python script assigns the value ‘YahooDSP’ to the ‘Campaign Maturity’ column in the output DataFrame if the ‘Campaign’ column contains the string ‘FR’ (case-insensitive) and the ‘Campaign Maturity’ column is blank. The script then prints the tableized version of the output DataFrame.
Walking Through the Code
- Define column constants for the input and output DataFrames.
- Check if the ‘Campaign’ column in the input DataFrame contains the string ‘FR’ (case-insensitive) and the ‘Campaign Maturity’ column is blank.
- Assign the selected columns from the input DataFrame to the output DataFrame where the conditions are true.
- Set the value ‘France’ in the ‘Campaign Maturity’ column of the output DataFrame.
- Print the tableized version of the output DataFrame.
Vitals
- Script ID : 131
- Client ID / Customer ID: 1306922587 / 2
- Action Type: Bulk Upload (Preview)
- Item Changed: Campaign
- Output Columns: Account, Campaign, Campaign Maturity
- Linked Datasource: M1 Report
- Reference Datasource: None
- Owner: Byron Porter (bporter@marinsoftware.com)
- Created by Byron Porter on 2023-05-24 19:45
- Last Updated by Byron Porter 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
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_MATURITY = 'Campaign Maturity'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGN_MATURITY = 'Campaign Maturity'
# Check if RPT_COL_CAMPAIGN has the string 'GINSU' and RPT_COL_CAMPAIGN_MATURITY is blank
condition = (inputDf[RPT_COL_CAMPAIGN].str.contains('FR', case=True, na=False)) & (inputDf[RPT_COL_CAMPAIGN_MATURITY].isnull())
# Assign 'YahooDSP' to the 'Campaign Maturity' column in outputDf where the conditions are true
outputDf = inputDf.loc[condition, [BULK_COL_ACCOUNT, BULK_COL_CAMPAIGN, BULK_COL_CAMPAIGN_MATURITY]]
outputDf.loc[:, BULK_COL_CAMPAIGN_MATURITY] = 'France'
# Print the tableized version of the output DataFrame
print(tableize(outputDf))
Post generated on 2024-05-15 07:44:05 GMT