Generative AI Trends

All the latest news and trends
How to use Code Interpreter to analyze data and draw charts

shared by Naveen Kohli on Saturday, July 8, 2023 •

ChatGPT has introduced a new feature called Code Interpreter. The official description of this marketing pitch of this feature is as below.

It lets ChatGPT run code, optionally with access to files you've uploaded. You can ask ChatGPT to analyze data, create charts, edit files, perform math, etc.

Just the first two items "analyze data and create charts" were the trigger points for me to say, I have to use it. For a person who spends lot of time looking at the data, creating visual representation of the data to identify patterns, trends, anomalies etc., it is one feature that can save so much time and effort.

This feature is available to ChatGPT PLUS users only. This would mean that you will have buy $20/month subscription. After you grasp the power of this new feature, this subscription amount will seem nothing as compared to the time you are going to save.

How to enable Code Interpreter

In your CharGPT screen, you have three dots in the lower left corner next to your name. Click on it to bring up the menu. Click on Settings option.

Click on the Beta Features in the Settings view and toggle Code interpreter option.

After you have toggle this feature to ON, close this settings pop-up. Hover on GPT-4 tab in the main view. You will see option of Code interpreter. Click on it and you are ready to use this feature.

To upload the file, you will need to click on "+" sign in the left corner of the prompt text box. It is very easy to miss. But now I have told you, so you are all set.

Generate Trends Bar Chart

As ChatGPT's description suggests that I can upload data files. I decided to try with a simple analysis. I have raw data for monthly trends of some features. Currently it is represented in a web page as a simple table. I decided not to query database and to go with cut and paste of data from web page itself. I copied the data on to the notepad. I performed no clean up or tried to create proper CSV file or some format that we are used to generating. The file contained two columns, first column has month names and second column has numbers.

I intentionally did it this way to check how much intelligence ChatGPT to cleanse and transform the data in appropriate format. I uploaded the file.

After the file is uploaded, it is time to prompt ChatGPT to tell what do you want the Generative AI engine to do. I will keep repeating this mantra.. It is all about good prompting. This was my time using the new tool so I was not sure what to expect. I used the following prompt as first attempt.

this file contains monthly trends data. analyze it to generate a bar chart

I was very impressed with outcome. Few items I will mention here. ChatGPT figured out the data in the file is not well formatted. It started the conversation by telling me about it. It did not ask me to format. Instead, it told me that it is going to reformat the content. Following screenshot shows the first step it performed. ChatGPT showed me python code used to reformat the data along with the new input it generated.

After data was in correct format, ChatGPT wrote Python code to generate Bar Chart that I was expecting to get. Following is Python code snippet that ChatGPT generated.

import matplotlib.pyplot as plt

# Create a bar chart
plt.figure(figsize=(10,6))
plt.bar(data['Month'], data['Value'], color='blue')

# Add title and labels
plt.title('Monthly Trends')
plt.xlabel('Month')
plt.ylabel('Value')

# Display the plot
plt.show()

Following is the bar chart it generated.

I decided to repeat the same input data for same analysis. Second time it generated a vertical bar chart visualization. I am not surprised that two attempts generated two different type of plots. Again, it is all about the prompts. I never told the orientation of the plot. ChatGPT did the best it could do. It filled the gap by itself.

It is a great feature in ChatGPT. Again, it is available to PLUS users only.

I will conclude with some word of caution. Please be careful about the data that you are uploading. If the data is sensitive, I will suggest masking the sensitive information. If the numbers are sensitive as well, then normalize them using some base value that only you know about.

Once you are done with the work, delete the chat. ChatGPT does not keep Code Interpreter session active for long and removes the file. But I advice to assume the worst. Take all the precaution to not leave the chat in a state that someone else can use to look at the data you uploaded.

Tags: generative ai chatgpt code interpreter

Share this post
Recent Posts
July9
Limitations and risks associated with ChatGPT

Shared by Naveen Kohli

Time: 8:34 AM

July8
July8
July7
What is text to image Generative AI

Shared by Naveen Kohli

Time: 10:41 AM

Popular AI Tools