Back to Pandas Ai

Installation & Quickstart

docs/v3/getting-started.mdx

3.0.01.6 KB
Original Source

Installation

PandasAI requires Python 3.8+ <=3.11. We recommend using Poetry for dependency management:

bash
# Using poetry (recommended)
poetry add pandasai

# Alternative: using pip
pip install pandasai

Quick setup

In order to use PandasAI, you need a large language model (LLM). You can use any LLM, but for this guide we'll use OpenAI through the LiteLLM extension.

First, install the required extension:

bash
pip install pandasai-litellm

Then, import PandasAI and configure the LLM:

python
import pandasai as pai
from pandasai_litellm.litellm import LiteLLM

# Initialize LiteLLM with your OpenAI model
llm = LiteLLM(model="gpt-4.1-mini", api_key="YOUR_OPENAI_API_KEY")

# Configure PandasAI to use this LLM
pai.config.set({
    "llm": llm
})

Chat with your data

python
import pandasai as pai
from pandasai_litellm.litellm import LiteLLM

# Initialize LiteLLM with your OpenAI model
llm = LiteLLM(model="gpt-4.1-mini", api_key="YOUR_OPENAI_API_KEY")

# Configure PandasAI to use this LLM
pai.config.set({
    "llm": llm
})

# Load your data
df = pai.read_csv("data/companies.csv")

response = df.chat("What is the average revenue by region?")
print(response)

When you ask a question, PandasAI will use the LLM to generate the answer and output a response. Depending on your question, it can return different kind of responses:

  • string
  • dataframe
  • chart
  • number

Find it more about output data formats here.

Next Steps