Script 469: Automate Campaigns CampaignCategoryDim

Purpose

Set dimensions based on campaign name.

To Elaborate

The Python script aims to set dimensions based on the campaign name. It takes an input DataFrame and modifies the campaign category based on specific conditions. The modified DataFrame is then used to update the campaign category in the output DataFrame. Only campaigns with a changed strategy are included in the output.

Walking Through the Code

  1. The script defines column constants for the input and output DataFrames.
  2. The current date is stored in the variable “today”.
  3. The input DataFrame is printed using the “tableize” function.
  4. A temporary field name is created by appending “_new” to the campaign category column name.
  5. The temporary field is initialized with NaN values.
  6. Conditions are applied to the input DataFrame using the “loc” function to set the temporary field based on the campaign and publisher names.
  7. The modified input DataFrame is printed using the “tableize” function.
  8. The “duplicated” function is used to check for duplicated indices in the input DataFrame.
  9. The campaign category from the temporary field is copied to the output DataFrame.
  10. The output DataFrame is filtered to include only campaigns with a changed strategy.
  11. The final output DataFrame is printed.

Vitals

  • Script ID : 469
  • Client ID / Customer ID: 1306925055 / 60269347
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, Campaign Category
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: Grégory Pantaine (gpantaine@marinsoftware.com)
  • Created by Grégory Pantaine on 2023-11-01 10:26
  • Last Updated by Grégory Pantaine 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
34
35
36
37
38
39
40
41
42
# Author: Gregory Pantaine
# Created: 2023-11-01
# Description: set dimensions based on campaign name
# Scripts name: Automate-Campaigns-CampaignCategoryDim
# Report name (M1): Automate-Campaigns-SetDimensionCampaignCategory


RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_PUB_NAME = 'Publisher Name'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_CATEGORY = 'Campaign Category'
BULK_COL_ACCOUNT = 'Account'
BULK_COL_PUB_NAME = 'Publisher Name'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_CAMPAIGN_CATEGORY = 'Campaign Category'

#outputDf[BULK_COL_CAMPAIGN_CATEGORY] = "<<YOUR VALUE>>"

today = datetime.datetime.now(CLIENT_TIMEZONE).date()
print(tableize(inputDf))



TMP_FIELD = BULK_COL_CAMPAIGN_CATEGORY + '_new'
# blank out tmp field
inputDf[TMP_FIELD] = numpy.nan
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('Brand', case=False)) , TMP_FIELD ] = 'Brand'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('Build Aviator', case=False)) , TMP_FIELD ] = 'Build Aviator'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('Shopping', case=False)) , TMP_FIELD ] = 'Shopping'
inputDf.loc[ (inputDf[RPT_COL_CAMPAIGN].str.contains('Tool Hire', case=False)) , TMP_FIELD ] = 'Tool Hire'
inputDf.loc[ (inputDf[RPT_COL_PUB_NAME].str.contains('SocialMoov', case=False)) , TMP_FIELD ] = 'Facebook'

print(tableize(inputDf))

print(inputDf.index.duplicated())

# copy new strategy to output
outputDf.loc[:,BULK_COL_CAMPAIGN_CATEGORY] = inputDf.loc[:, TMP_FIELD]

# only include campaigns with changed strategy in bulk file
outputDf = outputDf[ inputDf[TMP_FIELD].notnull() & (inputDf[BULK_COL_CAMPAIGN_CATEGORY] != inputDf[TMP_FIELD]) ]

Post generated on 2024-03-10 06:34:12 GMT

comments powered by Disqus