PandasAI
PandasAI is a Python library that enables users to ask questions of their data in natural language. It simplifies data interaction for non-technical users and saves time for technical users by generating answers and charts from pandas DataFrames. It is designed for anyone working with tabular data who wants to query it conversationally.
✨ Key features
- Natural language queries on pandas DataFrames
- Generates charts and visualizations from questions
- Supports multiple DataFrames in a single query
- Integrates with various LLMs via LiteLLM
- Optional Docker sandbox for secure code execution
- Simple configuration via pai.config.set
🎯 Use cases
- Ask business questions about sales data without SQL
- Generate histograms and other charts from data
- Join and query multiple related datasets conversationally
- Prototype data analysis workflows quickly
- Enable non-technical stakeholders to explore data
📦 Installation
🧰 Requirements: Python 3.8+ <=3.11, an API key for the chosen LLM (e.g., OpenAI), and optionally Docker for the sandbox.
pip install pandasai
pip install pandasai-litellm
Or with poetry:
poetry add pandasai
poetry add pandasai-litellm
🚀 Usage
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)
⚠️ Good to know
The library requires Python 3.8+ <=3.11 and an LLM API key; the repository includes an ee directory with a separate license, and the project is open source under MIT except for that directory.
❓ FAQ
What Python versions are supported?
Python 3.8+ up to 3.11 is required.
How do I configure an LLM?
You initialize an LLM (e.g., LiteLLM with a model and API key) and set it via pai.config.set({"llm": llm}).
Can I query multiple DataFrames at once?
Yes, you can pass multiple DataFrames to pai.chat() and ask questions that relate them.
Is there a way to run code securely?
Yes, you can use the Docker sandbox by installing pandasai-docker and using DockerSandbox to execute queries in an isolated environment.
📊 Repository
🤖 Overview, features, install steps and FAQ were generated from the project's README on Sep 4, 2026. Always check the original source before running commands.