Lesson 34 · Python for Banking and Finance
Automating Banking Workflows with Python: Practical Training for Financial Efficiency
This lesson will teach you how to use Python to automate repetitive banking tasks. Automation is important in banking because it improves efficiency,…
- CoursePython for Banking and Finance
- Lesson34 of 24
- Video20 min
- FormatJupyter notebook · 12 code cells
What you'll learn
- Understanding the Data for Banking Automation
- Beginner Example 1: Filter High-Value Transactions
- Beginner Example 2: Select Online Transactions
- Beginner Example 3: Count Transactions per Customer
- Intermediate Example 1: Merge Transactions and Customer Data
- Intermediate Example 2: Flag Suspicious Large Debits
- Intermediate Example 3: Automate Daily Transaction Summary
- Advanced Example 1: Batch Export Suspicious Transactions
Data
No separate download needed — the notebook creates or downloads everything it uses.
📓 Full notebook
Download .ipynbAutomating Banking Workflows with Python#
- This lesson will teach you how to use Python to automate repetitive banking tasks.
- Automation is important in banking because it improves efficiency, reduces errors, and allows staff to focus on high-value work.
- You will learn to organize transaction data, detect suspicious activity, and streamline operations using common Python patterns.
- By the end, you will be able to build simple automation scripts and understand how banks use automation daily.
import pandas as pd
import numpy as np
import warnings
warnings.filterwarnings('ignore')
Understanding the Data for Banking Automation#
- Each dataset in banking represents different aspects, such as transactions, customers, or account types.
- Data tables are usually structured with rows (records) and columns (fields/features).
- Beginners often make mistakes like: using the wrong column as unique ID, forgetting to check for duplicates, or mixing up datatypes (dates vs strings).
- Carefully explore your datasets before building automations to avoid costly mistakes later.
np.random.seed(42)
n_transactions = 1000
n_customers = 200
df = pd.DataFrame({
'transaction_id': range(1, n_transactions + 1),
'customer_id': np.random.choice([f'CUST_{i:04d}' for i in range(1, n_customers + 1)], n_transactions),
'amount': np.round(np.random.normal(150, 60, n_transactions), 2),
'transaction_type': np.random.choice(['Debit', 'Credit'], n_transactions),
'channel': np.random.choice(['ATM', 'Online', 'Branch', 'POS'], n_transactions),
'date': pd.date_range(start='2024-01-01', periods=n_transactions, freq='h')
})
print(df.shape)
print(df.head(3))
customer_ids = [f'CUST_{i:04d}' for i in range(1, 201)]
customers = pd.DataFrame({
'customer_id': customer_ids,
'segment': ['Retail'] * 150 + ['Business'] * 50,
'region': ['Metro'] * 100 + ['Regional'] * 100
})
print(customers.shape)
print(customers.head(3))
np.random.seed(42)
accounts = pd.DataFrame({
'account_id': [f'ACC_{i:05d}' for i in range(1, 201)],
'customer_id': customer_ids,
'account_type': np.random.choice(['Savings', 'Cheque', 'Credit'], size=200),
'open_date': pd.date_range(start='2015-01-01', periods=200, freq='30D')
})
print(accounts.shape)
print(accounts.head(3))
Beginner Example 1: Filter High-Value Transactions#
- Learn to select transactions above a certain value.
- Filtering is a simple automation that supports fraud detection and reporting.
high_value = df[df['amount'] > 250]
print(high_value.head(3))
print(f'Total high-value transactions: {len(high_value)}')
Beginner Example 2: Select Online Transactions#
- Isolate transactions performed through the 'Online' channel.
- This helps business teams analyze digital banking trends.
online_txns = df[df['channel'] == 'Online']
print(online_txns.head(3))
print(f'Number of online transactions: {len(online_txns)}')
Beginner Example 3: Count Transactions per Customer#
- Count total transactions for each customer.
- Summarizing by customer supports personalized offers or flagging inactive accounts.
txn_count = df.groupby('customer_id').size().reset_index(name='txn_count')
print(txn_count.head(3))
Intermediate Example 1: Merge Transactions and Customer Data#
- Enrich transaction logs with customer segment and region information.
- Merging datasets is a key banking automation for reporting or compliance.
merged = pd.merge(df, customers, on='customer_id', how='left')
print(merged.head(3))
Intermediate Example 2: Flag Suspicious Large Debits#
- Automate the detection of large debit transactions for monitoring fraud risks.
- This enables proactive alerts and compliance.
merged['suspicious_flag'] = np.where((merged['amount'] > 400) & (merged['transaction_type'] == 'Debit'), 1, 0)
print(merged[['transaction_id', 'amount', 'transaction_type', 'suspicious_flag']].head(5))
print(f'Suspicious transactions detected: {merged.suspicious_flag.sum()}')
Intermediate Example 3: Automate Daily Transaction Summary#
- Automate daily summary reports by aggregating transaction amounts and counts by day.
- Daily reporting reduces manual work and errors.
df['date_only'] = df['date'].dt.date
daily_summary = df.groupby('date_only').agg({'amount':['sum','count']})
daily_summary.columns = ['total_amount', 'txn_count']
print(daily_summary.head(3))
Advanced Example 1: Batch Export Suspicious Transactions#
- Automate exporting a CSV of flagged suspicious transactions for compliance reviews.
- Exporting is a key part of workflow automation in banking.
suspicious_txns = merged[merged['suspicious_flag'] == 1]
suspicious_txns.to_csv('suspicious_transactions.csv', index=False)
Advanced Example 2: Automate Report Distribution via Email (Simulated)#
- Although we will not send real emails, automating report saving prepares data for downstream tasks.
- In real banking workflows, you often automate emailing reports to compliance officers.
# Placeholder for future email automation. Here we simulate report preparation.
with open('report_ready.txt', 'w') as f:
f.write('Compliance report is ready for distribution.')
Great work completing the automation lesson!#
- Practice by applying these steps to your own datasets.
- For step-by-step videos, search for 'Banking Data Automation Python' on YouTube.
- You are now ready to tackle real-world banking automation scenarios!
Found this useful?
All lessons, notebooks and datasets here are free. If they helped you, a coffee keeps new lessons coming.



