Code Interpreter
Code Interpreter is a powerful tool that lets you run Python code directly in your chat conversations. You can analyze data, create visualizations, solve complex computational problems, and process files without leaving the chat interface.
Key Features
- Secure Python Execution: Run Python code in a protected environment
- Data Analysis & Visualization: Analyze data and create charts with popular libraries
- File Input & Output: Import files for analysis and export results
- Internet Access: Access external data sources when needed
- Pre-installed Packages: Use dozens of pre-installed libraries for data science, visualization, and more
Code Interpreter has limited resources and runtime. It’s designed for small to medium-sized tasks and may not be suitable for processing very large datasets or performing computationally intensive operations. For extensive data processing or long-running tasks, consider using a dedicated development environment.
Example Workflows
Code interpreter is invoked automatically. If you’d like to force interpreter usage type /code
and select the code interpreter before entering your query.
Data Analysis
Upload a CSV of your dataset
Upload your data file by dragging and dropping it into the chat or using the file upload button.
Ask specific analysis questions
How much of the sales were for people above the age of 50? Give me a barchart grouped by age in bins of 10 years
The Code Interpreter will analyze your data and generate visualizations based on your request.
Expand the Image
Click the image to expand it fullscreen. You can download and copy the file to clipboard.
Request data filtering and export
You can also use interpreter to create new files:
Give me a new CSV with only the electronics purchases
Code Interpreter will filter the data and provide a downloadable CSV file with the requested subset.
Now just hit download on the file to get your new CSV.
Image Processing
Request specific image modifications
Make this image black and white and flip the image horizontally
Code Interpreter will process your image with the requested transformations.
Expand the Image
Click the image to expand it fullscreen. You can download and copy the file to clipboard.
Ask for optimization
Can you optimize it as a png for web?
Code Interpreter will compress and optimize the image for web usage while maintaining quality.
Example Use Cases
Data Analysis
Analyze CSV, Excel, or database files to extract insights, create summaries, or find patterns:
Can you analyze this sales data and tell me which products performed best in Q4?
Give me the mean, median, and standard deviation of the sales figures.
Visualization
Create charts, graphs, and visual representations of your data:
Give me a word cloud of the text above
Generate a heatmap showing the correlation between these variables.
Computation
Give me the first 50 fibonacci numbers as a text file.
Calculate the positon of a satellite given the following parameters: <insert parameters>
Image Processing
Analyze, modify, or generate images:
Apply a red filter to this photo and a strong blur.
Grab a 100x100 pixel crop from the center of this photo
File Conversion
Transform files between different formats:
Convert this image to one optimized for the web.
Convert this Word document to a pdf.
Available Packages
Code Interpreter comes with many pre-installed Python libraries, including:
- Data Analysis: pandas, numpy, scipy, scikit-learn
- Visualization: matplotlib, plotly, seaborn, altair
- Image Processing: pillow, opencv-python
- Document Processing: pypdf, pdfminer, openpyxl
- Web & Network: requests, httpx, beautifulsoup4
- Math & Science: sympy, mpmath, statsmodels
It also includes useful command-line tools like ffmpeg, imagemagick, pandoc, and more for advanced operations.
AI will automatically install missing packages for you.
Tips for Best Results
-
Be specific about your goals: The more specific you are, the better the AI can tailor the code.
-
Use for complex calculations: Even for simple math, using Code Interpreter often gives more reliable results than asking in chat.
-
Upload relevant files: Attach datasets, images, or documents that you want to analyze.
-
Break down complex tasks: For multi-step analysis, consider breaking your request into smaller steps.
-
Review and iterate: If the results aren’t quite what you need, explain what you’d like changed.
For frequent data analysis, you can create a custom prompt that automatically uses Code Interpreter for specific types of tasks.