Skip to main content
HomeTutorialsArtificial Intelligence (AI)

How to Use ChatGPT Code Interpreter

Everything you need to know about OpenAI’s ChatGPT advanced data analysis, formerly Code Interpreter.
Updated Jul 28, 2024  · 9 min read

OpenAI's ChatGPT has taken the world by storm with its remarkable text-generation abilities. The chatbot continues to captivate users by generating charts and maps and transforming images into videos, thanks to a feature formerly called Code Interpreter.

Initially launched as a feature for ChatGPT Plus subscribers, it has become a default capability with the GPT-4o model. This feature enables ChatGPT to write and execute computer code, performing complex tasks such as calculations, data analysis, and generating visualizations.

This article gives an overview of how you can use ChatGPT Code Interpreter functionality with the help of a few example use cases.

AI Upskilling for Beginners

Learn the fundamentals of AI and ChatGPT from scratch.
Learn AI for Free

What is ChatGPT Code Interpreter?

ChatGPT is a chatbot that responds to questions using a technology known as a large language model (LLM). This technology works by predicting the next word in a sequence to form coherent responses. However, when the code interpreter feature is activated, ChatGPT's capabilities are significantly enhanced.

With the Code Interpreter enabled, ChatGPT can write and execute computer code to provide answers. This feature, introduced by OpenAI, allows the chatbot to perform tasks it couldn't do before. For instance, it can carry out complex calculations, generate charts based on user-uploaded data, and more, all through code execution.

The introduction of the Code Interpreter is seen by some as a way to reduce inaccuracies, a common issue associated with LLMs. By executing code to find answers, the chatbot can provide more precise and accurate responses, enhancing the overall user experience.

Technically speaking, the ChatGPT model has access to a Python interpreter in a sandbox environment, and it can not only write code but also execute it in a Python environment and return the answers. If the code fails (as it does many times), it can also debug the code reading the callback messages and automatically enter the loop to fix the code and make it work.

The code interpreter feature stays active for the whole chat, but there's a time limit to prevent it from going on for too long. The cool thing is that you can run multiple pieces of code one after the other, and they can work together.

Plus, you can send files to this chat conversation. So, if your code needs to read data from a file, you can send that file over. And when your code is done, you can get the results back. For example, if your code makes a new file, you can download it and use it however you want. At the moment, the limit for input file size is roughly 500 MB.

Here’s a simple example of the Code Interpreter from official OpenAI documentation:

Code interpreter plugin performing logic calculations

Code interpreter plugin performing logic calculations

Getting Started with Code Interpreter

Update on May 16, 2024: OpenAI has rolled out enhancements to data analysis, formerly known as Advanced Data Analysis, or Code Interpreter.  The feature is now available in the new flagship model, GPT-4o, for ChatGPT Plus, Team, and Enterprise users. The enhancements include:

  • Direct file uploads from Google Drive and Microsoft OneDrive: Easily upload the latest file versions directly from your cloud storage.
  • Interactive tables and charts: Engage with data in a new expandable view, allowing real-time interaction and follow-up questions.
  • Customized and downloadable charts: You can customize bar, line, pie, and scatter plot charts and download them for presentations and documents.

These features are now available by default with GPT-4o. For more details, read the OpenAI announcement. This means you no longer need to manually enable Code Interpreter or Advanced Data Analysis as with previous ChatGPT versions.

Common Use-Cases of ChatGPT Code Interpreter

The most common use case of ChatGPT’s Code Interpreter that has come out so far is analyzing data (that's probably why it was renamed as simply data analysis).

For example, if you ask ChatGPT to find something interesting in your data, it can examine information like your financial records, health stats, or location details and give you some insights.

People working in finance have found it useful for tasks like studying stock prices or planning a budget. Researchers are also using this tool to make unique data visualizations. For instance, ChatGPT’s Code Interpreter created an interactive graph of the world population.

2022 World Population Map

Credits

Even though data analysis is the most common use case for now, theoretically, any task that requires logic and computation should be possible for ChatGPT’s Code Interpreter to achieve. From the initial user studies, OpenAI has identified these areas where the code interpreter is particularly very useful:

  • Solving mathematical problems, both quantitative and qualitative
  • Doing data analysis and visualization
  • Converting files between formats

Examples of Using ChatGPT Code Interpreter

Example 1 - Data analysis on a toy dataset

First, let’s try it out with a very simple dataset. This is what the dataset looks like:

Carat table

I will upload the CSV file and ask ChatGPT’s code interpreter to analyze the data through a simple prompt. You will see a plus sign in the message box which you can use to upload files.

Prompt

Once you input the prompt, the ChatGPT code interpreter starts processing. I can't display the entire output here since it's pretty big, as it includes the process itself, but here are a few insights extracted.

output visualizations

Having worked on this dataset before, I can tell this is relevant insight, and it’s impressive how fast it churned that out. Here is the story as well that we asked for:

Bulleted insights

This is pretty impressive. However, the dataset is relatively simple, with 6,000 rows and 7 columns—pretty clean and straightforward. Let’s try out this example with a dataset that’s more likely for the real world.

Access 60+ ChatGPT prompts for data science tasks in this ChatGPT Cheat Sheet for Data Science on DataCamp.

Example 2 - Data insights on a more complex dataset

In this example, the dataset is of Canadian CPI inflation from StatsCan. This is what the dataset looks like—it is raw, has duplicates, missing values, a lot of encoded information, and geographical coding.

Inflation data

Let’s see what kind of insights we can get from this dataset and a simple prompt.

prompt2

1. Developing the schema

dataset schema

2. Data cleaning

dataset analysis

3. Data visualization

4. Extracting insights

Insight extraction

This is impressive. It has done a decent job in understanding the data, cleaning the data, thinking of the appropriate visualization, then writing Python code to generate that visualization, and finally writing insights around it. It’s not perfect, but it’s very promising compared to all the automated insight tools we have seen in the past.

Do you want to learn how to use ChatGPT in a real-life end-to-end data science project? Check out this Guide to Using ChatGPT For Data Science Projects on DataCamp now.

Example 3 - Image animation using ChatGPT

You can also upload an image and have ChatGPT edit it. For example, I will upload an image of an apple and ask it to animate it.

animation prompt

It may ask you some clarifying questions, but eventually, it will write code to animate the image as you requested.

animation working process

output gif

Animated output (gif file) downloaded from ChatGPT's Code Interpreter

Conclusion

OpenAI's ChatGPT Code Interpreter is a groundbreaking feature that expands the capabilities of the AI-driven chatbot. By enabling the code interpreter, ChatGPT gains the ability to write and execute computer code, allowing it to perform complex tasks such as calculations, data analysis, and generating visualizations.

This feature not only enhances the accuracy and precision of ChatGPT's responses but also provides users with a more interactive and dynamic experience. From analyzing data to solving mathematical problems, the code interpreter opens up a wide range of possibilities for users, making ChatGPT a powerful tool for various applications.

If you want to level up your workflows and transform your business with ChatGPT, join our Introduction to ChatGPT course on DataCamp today and master the power of generative AI. Unlock endless possibilities and revolutionize your work today! Enroll here.

Introduction to ChatGPT Course

Get Started with ChatGPT

Start Now

FAQs

What is the main difference between the old Code Interpreter and the new GPT-4o model's data analysis capabilities?

The new GPT-4o model includes enhanced data analysis capabilities by default, which eliminates the need for manual activation. It also introduces new features such as direct file uploads from Google Drive and Microsoft OneDrive, interactive tables and charts, and customizable, downloadable charts for presentations and documents.

How can I upload files from Google Drive or Microsoft OneDrive to ChatGPT for analysis?

With the GPT-4o model, you can upload the latest file versions directly from your Google Drive or Microsoft OneDrive. This allows ChatGPT to quickly process various file types, including Google Sheets, Docs, Slides, and Microsoft Excel, Word, and PowerPoint files, streamlining the workflow for data analysis.

What types of charts can I customize and download using ChatGPT's new data analysis features?

You can customize and interact with bar, line, pie, and scatter plot charts during your conversation with ChatGPT. You can hover over chart elements, ask additional questions, select colors, and download the charts for use in presentations or documents.

Is the web browsing plugin still unavailable, and has it been replaced or reintroduced?

The web browsing plugin, initially removed due to security and privacy issues, has been reintroduced with enhanced safeguards. This allows users to access up-to-date information and perform web-based tasks securely.

Are there any privacy and security measures in place for the new data analysis features in ChatGPT?

Yes, OpenAI emphasizes trust and data privacy. They do not train on data from ChatGPT Team and Enterprise customers, and ChatGPT Plus users can opt out of training through their Data Controls. Additionally, OpenAI offers comprehensive security measures, including SAML SSO, compliance, and data encryption, to ensure user data is protected.

Earn a Top AI Certification

Demonstrate you can effectively and responsibly use AI.

Photo of Adel Nehme
Author
Adel Nehme
LinkedIn

Adel is a Data Science educator, speaker, and Evangelist at DataCamp where he has released various courses and live training on data analysis, machine learning, and data engineering. He is passionate about spreading data skills and data literacy throughout organizations and the intersection of technology and society. He has an MSc in Data Science and Business Analytics. In his free time, you can find him hanging out with his cat Louis.

Topics

Learn more about ChatGPT with these courses!

Course

Introduction to ChatGPT

1 hr
233K
Learn how to use ChatGPT. Discover best practices for writing prompts and explore common business use cases for the powerful AI tool.
See DetailsRight Arrow
Start Course
See MoreRight Arrow
Related

tutorial

How to Use ChatGPT Custom Instructions

Explore ChatGPT Custom Instructions feature. Learn how to fine-tune responses, explore use cases for teachers, entrepreneurs, and content creators.
Moez Ali's photo

Moez Ali

7 min

tutorial

How to Use ChatGPT for Sales

Discover the essential prompts and tips for getting the most out of ChatGPT for sales
Matt Crabtree's photo

Matt Crabtree

10 min

tutorial

A Beginner's Guide to ChatGPT Prompt Engineering

Discover how to get ChatGPT to give you the outputs you want by giving it the inputs it needs.
Matt Crabtree's photo

Matt Crabtree

6 min

tutorial

A Beginner's Guide to Using the ChatGPT API

This guide walks you through the basics of the ChatGPT API, demonstrating its potential in natural language processing and AI-driven communication.
Moez Ali's photo

Moez Ali

11 min

code-along

Using ChatGPT Code Interpreter for Data Science

In this live training, we use ChatGPT Code Interpreter to perform a data analysis workflow on an Airbnb dataset.
Adel Nehme's photo

Adel Nehme

code-along

Getting Started with the OpenAI API and ChatGPT

Get an introduction to the OpenAI API and the GPT-3 model.
Richie Cotton's photo

Richie Cotton

See MoreSee More