Unlock the Power of Open AI with PandasAI: Analyze Your Pandas DF with AI


The rapid advancements in artificial intelligence (AI) technology have revolutionized the way we interact with data. One such innovation is PandasAI, which enables users to analyze their Pandas data frames using AI capabilities. With PandasAI, you can easily ask questions and receive responses in natural language from your Pandas data frame. In this article, we will explore the power of PandasAI and how you can utilize it to analyze your data effectively.

How to Use PandasAI

To use PandasAI, you need to install the openai library and obtain an open AI API key. Once you have the API key, you can create an object called pandas_AI and supply it with llm, the openai wrapper, as an argument. After setting up the pandas_AI object, you can run queries on your Pandas data frame by invoking the pandas_AI.run() function. Let’s look at an example of how PandasAI can be used.


Suppose you have a Pandas data frame with three columns: country, GDP, and happiness index. You want to know which countries are the five happiest. With PandasAI, you can ask this question in natural language and receive an appropriate response. Here’s how you can implement this:

  1. Begin by importing the necessary libraries, including Pandas and OpenAI.
import openai
import pandas as pd
  1. Set up your openai API key and create an llm object.
openai.api_key = "your-api-key"
llm = openai.LanguageModel("text-davinci-002")
  1. Create the pandas_AI object by supplying llm as an argument.
pandas_AI = PandasAI(llm)
  1. Run the query on your Pandas data frame using pandas_AI.run().
query = "What are the five happiest countries?"
response = pandas_AI.run(df, query)

The output of this code will be the five countries with the highest happiness index in your data frame.

How Does It Work?

PandasAI works by utilizing the power of open-source language models, such as OpenAI and Hugging Face. These models use deep learning techniques to generate responses to natural language questions. PandasAI integrates these models with your Pandas data frame to create an interactive environment that allows you to ask questions and receive responses in natural language.

Advantages of Using PandasAI

Using PandasAI has several advantages that make it an efficient tool for data analysis. Some of these advantages include:

  1. It makes data analysis accessible to everyone, regardless of technical expertise.

  2. It allows you to interact with your data in natural language, making it easier to understand.

  3. It can help you identify patterns and trends that are difficult to detect using traditional data analysis methods.

  4. It can save you a lot of time by providing quick responses to your queries.

  5. It can be used for various applications, from financial analysis to customer support.

Open Assistant

Apart from PandasAI, Open Assistant is another open-source language model that can be used for data analysis. Open Assistant works similarly to PandasAI but requires a Hugging Face API key and a GPU to run. You can create an Open Assistant object by supplying it with the API key and the name of the model you want to use. Here’s an example of how you can implement Open Assistant:

import openai
from openai import OpenAI

openai.api_key = "your-api-key"
open_assistant = OpenAI(api_key=openai.api_key, model_name="text-davinci-002")

After setting up the Open Assistant object, you can run queries on your Pandas data frame using the open_assistant.ask() function.


  1. What is PandasAI, and how does it work?

PandasAI is an AI-powered tool that allows users to interact with their Pandas data frame using natural language queries. It works by integrating open-source language models with the data frame to provide responses to your queries.

  1. What are the advantages of using PandasAI?

Some of the advantages of using PandasAI include its accessibility, ease of use, ability to identify patterns and trends, and quick response times.

  1. What is Open Assistant, and how is it different from PandasAI?

Open Assistant is another open-source language model that can be used for data analysis. It works similarly to PandasAI but requires a Hugging Face API key and a GPU to run.

  1. How can I install PandasAI?

You can install PandasAI by using pip. Run the following command in your terminal:

pip install pandas-ai
  1. Can I use PandasAI and Open Assistant on the same data frame?

Yes, you can use PandasAI and Open Assistant simultaneously on the same data frame, leveraging the strengths of both tools.

Leave a Reply

Your email address will not be published. Required fields are marked *