TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Automate Accounting Tasks using Python

Build Solutions to Automate Repetitive Tasks for Financial Audits and Share them with Your Finance Colleagues to Improve their Productivity.

Samir Saci
TDS Archive
Published in
6 min readApr 27, 2021

--

A visual guide titled “Design Automation Tools for Excel Users” explains the steps to automate sales analytics tasks using Python. The image contains four steps: 1) “Data Analysis to provide Insights” with a graph icon, 2) “Automate the calculation using Python” with a calculator icon, 3) “Export your Python code in executable file (.exe)” with a robot icon, and 4) “Share your file with your colleagues” with a sharing file icon. The overall message is to help Excel users automate tasks.
Excel Automation — (Image by Author)

Are you looking to automate repetitive accounting tasks and improve your productivity?

In this article, we’ll explore how to build a Python solution that automatically extracts data from unstructured Excel files, processes it and compiles it into a single report for financial audits.

By following our steps, you can design an efficient tool to help your finance team analyze costs and identify trends over time, saving valuable time and resources.

Plus, we’ll show you how to share your Python script with colleagues without any prior experience with Python.

I. Automating Accounting Tasks with Python
1. Problem Statement: Extracting Data from Unstructured Excel Files
2. Objective: Building a Tool to Automate Data Extraction and Reporting
II. Building an Automated Data Extraction Solution with Python
1. Import Monthly Excel Reports and Process Data
2. Format columns and perform the calculations
III. Next Steps to Scale Your Solution
1. Sharing Your Tool with Finance Teams
2. Automatically create a PowerPoint to present the results
3. Generative AI: Boost your tool with GPT
3. Automate Data Extraction from SAP using VBA

Automating Accounting Tasks with Python

Problem Statement: Extracting Data from Unstructured Excel Files

You are working as a Data Analyst for a major Logistics Company.

Your colleagues from the finance team request your support in building a model to predict the P&L of warehouse operations.

A detailed monthly cost report for a logistics company, showing operational costs categorized by type (investment, renting, purchasing) for various equipment and tools such as reach trucks, batteries, pallet jacks, and more. Each row lists a specific asset with unit quantities, unit costs, and total costs under different categories like renting and investing. Columns include equipment names, units purchased or rented, and associated costs for a 30-day period ending August 31, 2017.
Example of Monthly Costs Report for May-2017 — (Image by Author)

You need to extract information from monthly reports built by accounting teams listing all the detailed costs by category

  • 20 Warehouses included in your study
  • Audit of the last 36 Months
  • 720 Excel Files in Total
  • 60 Item Costs to track
  • Three categories of costs: Investments, Rental, Purchasing

Building a Tool to Automate Data Extraction and Reporting

Your objective is to build a tool that will automatically extract data from each of these 720 Excel files, format it and combine everything in one report.

A breakdown of monthly expenses from May to September for various equipment types. The table categorizes each expense as rent or investment, showing the quantity and unit costs for each month. The equipment includes RF guns, printers, pallet jacks, and more. The table helps track changes in investment and rental costs over time, facilitating cost comparisons across months.
Example of Report for Audits — (Image by Author)

Finance will use this report to analyze the costs for the last 3 years and understand the trends.

Your tool will help get visibility in a single report without using extra resources to perform it manually.

🏫 Discover 70+ case studies using Python to automate manual tasks 🤖 and support business optimization 🏪 in this Cheat Sheet

Building an Automated Data Extraction Solution with Python

You will design a simple Python script that will perform:

  1. Open every Excel Report located in a folder
  2. Processing and cleaning data
  3. Build the monthly report following the format presented above
  4. Merge the monthly report with the global data frame
  5. Saving final results in an Excel file

Import Monthly Excel Reports and Process Data

There are a few important points here:

  • header parameter of pandas to only take the 5th (very useful with Excel files)
  • Fill nan with 0 to perform calculations on numeric values
  • Trim columns name: very useful in the situation where people are doing manual input (‘Unit Cost’ and ‘Unit Cost ‘ look the same for your users)

Format columns and perform the calculations

This part is linked to the report I processed; I share the code for reference here (Link).

💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.

Next Steps to Scale Your Solution

Sharing Your Tool with Finance Teams

Now that you’ve built your tool, you want to share it with Finance teams.

For your reference, performing these tasks full-time (1 headcount) took 2 weeks in my previous company.

Could you imagine the impact you would have if you could implement this simple tool?

If you want to know more,

If you follow the steps explained in this article, you will have an executable file (.exe) ready to share with your colleagues so they can run the script without Python.

Do you want to generate reports based on the data processed?

Automate PowerPoint Slide Creation with Python

Let us imagine that you need to prepare, every week, PowerPoint presentations based on the results generated by this excel file.

How can you automate this process?

With Python, we can automatically generate the PowerPoint with visuals and comments.

  • Automate the Excel file generation using the tool presented in this article.
  • Extract results from this Excel document using PowerPoint and create visuals with comments.
  • Automatically put the visuals and insights in a PowerPoint presentation.
A flowchart illustrating the automated creation of PowerPoint slides for supply chain reports. It starts with 5 weeks of operational data from a warehouse management system database. SQL queries extract prepared order lines, which are processed by Python scripts to calculate KPIs. The output is a PowerPoint report with weekly warehouse workload and order profile visuals.
Example of an other workflow to generate PowerPoin Slides — (Image by Author)

What is the the final result?

You can generate a deck with slides like the example below

A PowerPoint slide titled “Warehouse Workload (WEEK-1)” and “Order Profile” displaying two visuals generated with Python. The left chart shows the warehouse workload per day with a bar chart, and the right chart displays the order profile with the split of orders by the number of lines. Below each chart are insights, such as the number of orders and lines prepared during the week. A highlighted comment area at the top provides updated information and comments.
Final Results — (Image by Author)

For more information on how to implement this workflow, check this article.

Have you heard about Generative AI?

Generative AI: GPT for Process Optimization

I started experimenting with designing a LangChain Agent connected to a TMS following the adoption of large language models (LLMs),

A diagram showing an automated supply chain control tower workflow with GPT and Langchain starting with ambiguous input (represented by question marks), proceeding through SQL queries, machine learning analysis, and generating insights that are communicated to users in an understandable form.
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] — (Image by Author)

The outputs are pretty impressive; the GPT-powered agent can automate any task.

What if we want to automate accounting tasks with GPT?

With ChatGPT's new feature, “GPTs,” we can create an agent equipped with documentation, Python scripts, and data.

This diagram outlines how the custom GPTs for Supply Chain Analytics work. It starts with the user asking a question or requesting an analysis, the agent retrieves data (from the provided dataset or sample), processes it with a core Python script, and returns output as charts or comments. The flow clearly illustrates three key steps: initial prompt, data processing using the script, and final analysis outputs that is used by “The Supply Chain Analyst”.
Architecture of an advanced “GPT” agent

In this example, we can create an agent that interacts with users to create reports.

  • We provide a core module with the Python script presented in this article
  • We add prompts for the context and user interaction management
  • We use GPT intelligence to improve the outputs

For more details,

How can you collect data automatically from systems?

Advancing to Automated Data Extraction from ERPs

Before building the report, you need to collect the data from your ERP.

If you are using SAP, you may be interested in this series of articles about ERP Automation.

About Me

Let’s connect on Linkedin and Twitter, I am a Supply Chain Engineer using data analytics to improve logistics operations and reduce costs.

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

If interested in Data Analytics and Supply Chain, look at my website.

💌 New articles straight in your inbox for free: Newsletter
📘 Boost your Productivity with Data Analytics: Productivity Cheat Sheet

--

--

Samir Saci
Samir Saci

Written by Samir Saci

Top Supply Chain Analytics Writer — Case studies using Data Science for Supply Chain Sustainability 🌳 and Productivity: https://bit.ly/supply-chain-cheat

Responses (3)