Automate Excel using Python + ChatGPT-4o 🤯
Introduction
In this blog post, I will explore how to automate Excel with ChatGPT4o, leveraging its capabilities to streamline various Excel tasks such as merging workbooks and creating interactive charts. The new ChatGPT version is not only faster but also offers more features that enhance productivity. Let’s dive into the details!
Getting Started with ChatGPT4o
OpenAI recently released ChatGPT 4.o, which is twice as fast as its predecessor. This version is available for free, making it accessible for anyone looking to enhance their Excel skills. One of the exciting features is the ability to upload images and spreadsheets directly to ChatGPT, which can be particularly useful for automating tasks.
Merging Excel Workbooks
To begin, I have a folder containing multiple Excel files with sales data from different cities. The first task is to consolidate these files into a single workbook. I start by opening one of the Excel files and taking a screenshot of the first few rows to illustrate the structure to ChatGPT.
Next, I paste this screenshot into ChatGPT and provide a prompt detailing my request: merging the data from these files into a single workbook. After pressing enter, I receive a code snippet along with instructions on how to use it. Remarkably, ChatGPT could generate the code without needing the image since all files shared the same format.
After copying the code into a Python file and executing it, I validate the result by filtering the new Excel file. All cities are successfully included in the merged data, showcasing the effectiveness of using ChatGPT for this task.
Creating Interactive Charts
Now that the data is consolidated, the next step is to visualize it. One of my favorite libraries for creating stunning visualizations is PyEcharts. I decide to create a calendar heatmap to display the sales data for 2023.
To achieve this, I copy a sample code from the PyEcharts gallery and paste it into ChatGPT along with the merged workbook. I ask ChatGPT to generate an interactive heatmap for each city, resulting in separate HTML files for each visualization.
After executing the code, I find the HTML files in my directory and open one to see the interactive sales heatmap. I ensure that the data matches the original workbook by cross-referencing the figures, confirming that everything is accurate.
Combining Scripts for Efficiency
With both the merging and visualization scripts working, I decide to streamline the process by combining them into a single script. I ask ChatGPT how to integrate both functionalities, and it provides the necessary code adjustments.
After creating a new Python file and executing the combined script, I confirm that it still functions correctly, generating both the merged data and the interactive heatmap in one go. This consolidation significantly enhances my workflow efficiency.
Final Thoughts
Throughout this process, I learned that being specific with prompts in ChatGPT greatly influences the outcomes. I also discovered that I could enhance my code by chaining Pandas methods for more concise transformations, similar to Power Query.
In conclusion, using ChatGPT4o to automate Excel with ChatGPT4o has proven to be an invaluable asset, simplifying tasks that once took considerable time and effort. I hope this inspires you to explore the potential of ChatGPT in your own Excel projects.
Conclusion
This blog post covered how to automate various Excel tasks using ChatGPT4o, including merging workbooks and creating interactive charts. The new features of ChatGPT4o make these processes faster and more efficient, showcasing the power of AI in data management. Thanks for reading!