Script 991: Percentage Difference Column Alert
Purpose
The script alerts a Program Manager when the percentage difference in a dataset is 15% or more, either positively or negatively.
To Elaborate
The Python script is designed to monitor changes in a dataset by calculating the percentage difference for each entry. If the percentage difference is 15% or more, either as an increase or a decrease, it triggers an alert for the Program Manager. This alert is recorded in a specific column of the dataset, allowing the manager to quickly identify significant changes that may require attention. The script ensures that only substantial changes are flagged, helping to focus on critical data variations and streamline decision-making processes.
Walking Through the Code
- Data Preparation
- The script begins by loading the primary data source into a DataFrame named
inputDf
. - It defines several column names that are used throughout the script, such as ‘Campaign’, ‘Account’, and ‘Percentage Difference’.
- The ‘AUTOMATION_ALERT’ column in
inputDf
is cleared by setting its values toNaN
, preparing it for new alert data.
- The script begins by loading the primary data source into a DataFrame named
- Alert Criteria Application
- The script initializes the ‘AUTOMATION_ALERT’ column in
outputDf
withNaN
values. - It then applies criteria to determine if the percentage difference is 15% or more, either positively or negatively.
- If the condition for a high increase is met, the script sets the alert message to ‘Alert: High Increase’.
- If the condition for a high decrease is met, it sets the alert message to ‘Alert: High Decrease’.
- For all other cases, the alert remains as ‘NaN’, indicating no significant change.
- The script initializes the ‘AUTOMATION_ALERT’ column in
- Output
- The script prints the updated DataFrame, showing the alerts for easy review by the Program Manager.
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-11-27 06:58:46 GMT