Script 1363: Daily Budget Upload

Purpose

The Python script processes and uploads daily budget data from a primary data source, ensuring unique entries based on specific criteria.

To Elaborate

The Python script named ‘Daily Budget Upload’ is designed to handle the processing and uploading of daily budget data from a specified data source. The script extracts relevant columns from the input data, such as ‘Date’, ‘Pub. ID’, and ‘Daily Budget’, and maps them to corresponding output columns. It ensures that each entry in the output data is unique by removing duplicates based on the ‘Comments’ column, which corresponds to ‘Campaign Pub. ID’ in the input data. This process is crucial for maintaining accurate and non-redundant budget records, which are essential for effective financial planning and reporting. The script is structured to allow for easy adjustments to the data source and column mappings, making it adaptable to different datasets and business requirements.

Walking Through the Code

  1. Data Source and Column Mapping
    • The script begins by defining the primary data source and the relevant columns needed for processing. It extracts columns such as ‘Group’, ‘Date’, ‘Account’, ‘Campaign’, ‘Daily Budget’, ‘Pub. ID’, and ‘Campaign Pub. ID’ from the input data.
  2. Output Data Preparation
    • The script maps the extracted input columns to the output data frame, assigning them to new column names like ‘Date’, ‘Group ID’, ‘Daily Budget Upload Conv’, and ‘Comments’. This step ensures that the output data is structured correctly for further use.
  3. Duplicate Removal
    • To maintain data integrity, the script removes duplicate entries from the output data frame based on the ‘Comments’ column, which corresponds to ‘Campaign Pub. ID’. This ensures that each campaign’s budget is only recorded once.
  4. User Code Execution
    • The script concludes by printing a preview of the input data using the tableize function, allowing users to verify the initial data before further processing.

Vitals

  • Script ID : 1363
  • Client ID / Customer ID: 1306927965 / 60270405
  • Action Type: Revenue Upload
  • Item Changed: None
  • Output Columns: Date, Group ID, Comments, Daily Budget Upload Conv
  • Linked Datasource: FTP/Email Feed
  • Reference Datasource: None
  • Owner: Tom McCaughey (tmccaughey@marinsoftware.com)
  • Created by Tom McCaughey on 2024-09-02 13:26
  • Last Updated by Tom McCaughey on 2024-09-03 15:20
> 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
##
## name: Daily Budget Upload
## description:
##  
## 
## author: 
## created: 2024-09-02
## 

today = datetime.datetime.now(CLIENT_TIMEZONE).date()

# primary data source and columns
inputDf = dataSourceDict["1"]
RPT_COL_GROUP = 'Group'
RPT_COL_DATE = 'Date'
RPT_COL_ACCOUNT = 'Account'
RPT_COL_CAMPAIGN = 'Campaign'
RPT_COL_DAILY_BUDGET = 'Daily Budget'
RPT_COL_PUB_ID = 'Pub. ID'
RPT_COL_CAMPAIGN_PUB_ID = 'Campaign Pub. ID'

# output columns and initial values
REVENUE_COL_DATE = 'Date'
REVENUE_COL_GROUP_ID = 'Group ID'
REVENUE_COL_DAILY_BUDGET_UPLOAD_CONV = 'Daily Budget Upload Conv'
REVENUE_COL_COMMENTS = 'Comments'
outputDf[REVENUE_COL_DATE] = inputDf['Date']
outputDf[REVENUE_COL_GROUP_ID] = inputDf['Pub. ID']
outputDf[REVENUE_COL_DAILY_BUDGET_UPLOAD_CONV] = inputDf['Daily Budget']
outputDf[REVENUE_COL_COMMENTS] = inputDf['Campaign Pub. ID']

outputDf = outputDf.drop_duplicates(subset=['Comments'], keep='first')



# user code start here
print(tableize(inputDf.head()))

Post generated on 2024-11-27 06:58:46 GMT

comments powered by Disqus