Script 991: Percentage Difference Column Alert

Purpose

Alerts Program Manager whenever The Percentage Difference is higher or equal to 15%

To Elaborate

This Python script is designed to alert the Program Manager whenever the Percentage Difference in a dataset is equal to or higher than 15%. The script takes an input DataFrame and applies criteria to generate values for the ‘AUTOMATION_ALERT’ column. If the Percentage Difference meets the specified criteria, the ‘AUTOMATION_ALERT’ column will be updated with an appropriate alert message. The updated DataFrame is then printed.

Walking Through the Code

  1. The script starts by importing the necessary libraries and defining the input DataFrame as inputDf.
  2. The script defines the column names for the primary data source and the output DataFrame.
  3. The existing data in the ‘AUTOMATION_ALERT’ column of the input DataFrame is cleared.
  4. The input DataFrame is printed using the tableize function.
  5. The script creates a new column called ‘AUTOMATION_ALERT’ in the output DataFrame and initializes it with NaN values.
  6. The script applies criteria to identify rows where the Percentage Difference is equal to or higher than 15% and rows where it is equal to or lower than -15%.
  7. The ‘AUTOMATION_ALERT’ column is updated with appropriate alert messages based on the criteria.
  8. Rows that do not meet the specified criteria have the ‘AUTOMATION_ALERT’ column set to NaN.
  9. The updated output DataFrame is printed using the tableize function.

Vitals

  • Script ID : 991
  • Client ID / Customer ID: 1306926629 / 60270083
  • Action Type: Bulk Upload
  • Item Changed: Campaign
  • Output Columns: Account, Campaign, AUTOMATION_ALERT
  • Linked Datasource: M1 Report
  • Reference Datasource: None
  • Owner: dwaidhas@marinsoftware.com (dwaidhas@marinsoftware.com)
  • Created by dwaidhas@marinsoftware.com on 2024-04-22 17:44
  • Last Updated by dwaidhas@marinsoftware.com on 2024-05-07 18:50
> 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
##
## name: Percentage Difference Column Alert
## description:
##  Alerts Program Manager whenever The Percentage Difference is higher or equal to 15%
## 
## author: Dana Waidhas 
## created: 2024-04-22
## 

inputDf = dataSourceDict["1"]

# primary data source and columns
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN_STATUS = 'Campaign Status'
RPT_COL_SBA_STRATEGY = 'SBA Strategy'
RPT_COL_PERCENTAGE_DIFFERENCE = 'Percentage Difference'
RPT_COL_AUTOMATION_ALERT = 'AUTOMATION_ALERT'

# Clear existing data in the 'AUTOMATION_ALERT' column
inputDf[RPT_COL_AUTOMATION_ALERT] = np.nan

# output columns and initial values
BULK_COL_ACCOUNT = 'Account'
BULK_COL_CAMPAIGN = 'Campaign'
BULK_COL_AUTOMATION_ALERT = 'AUTOMATION_ALERT'

print(tableize(inputDf.head()))

# Apply criteria to generate values for 'AUTOMATION_ALERT' column
outputDf['AUTOMATION_ALERT'] = np.nan
should_alert_high = inputDf['Percentage Difference'] >= 0.15
should_alert_low = inputDf['Percentage Difference'] <= -0.15
outputDf.loc[should_alert_high, 'AUTOMATION_ALERT'] = 'Alert: High Increase'
outputDf.loc[should_alert_low, 'AUTOMATION_ALERT'] = 'Alert: High Decrease'
outputDf.loc[~(should_alert_high | should_alert_low), 'AUTOMATION_ALERT'] = 'NaN'  # Blank for other cases


# Print the updated DataFrame
print(tableize(outputDf.head()))

Post generated on 2024-05-15 07:44:05 GMT

comments powered by Disqus