MCPcopy
hub / github.com/sinaptik-ai/pandas-ai

github.com/sinaptik-ai/pandas-ai @v3.0.0a20 sqlite

repository ↗ · DeepWiki ↗ · release v3.0.0a20 ↗
1,678 symbols 6,186 edges 189 files 566 documented · 34%
README

PandasAI

Release CI CD Coverage Discord Downloads License: MIT Open in Colab

PandasAI is a Python platform that makes it easy to ask questions to your data in natural language. It helps non-technical users to interact with their data in a more natural way, and it helps technical users to save time, and effort when working with data.

🔧 Getting started

You can find the full documentation for PandasAI here.

📚 Using the library

Python Requirements

Python version 3.8+ <=3.11

📦 Installation

You can install the PandasAI library using pip or poetry.

With pip:

pip install "pandasai>=3.0.0b2"

With poetry:

poetry add "pandasai>=3.0.0b2"

💻 Usage

Ask questions

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)

Or you can ask more complex questions:

df.chat(
    "What is the total sales for the top 3 countries by sales?"
)
The total sales for the top 3 countries by sales is 16500.

Visualize charts

You can also ask PandasAI to generate charts for you:

df.chat(
    "Plot the histogram of countries showing for each one the gd. Use different colors for each bar",
)

Chart

Multiple DataFrames

You can also pass in multiple dataframes to PandasAI and ask questions relating them.

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
})

employees_data = {
    'EmployeeID': [1, 2, 3, 4, 5],
    'Name': ['John', 'Emma', 'Liam', 'Olivia', 'William'],
    'Department': ['HR', 'Sales', 'IT', 'Marketing', 'Finance']
}

salaries_data = {
    'EmployeeID': [1, 2, 3, 4, 5],
    'Salary': [5000, 6000, 4500, 7000, 5500]
}

employees_df = pai.DataFrame(employees_data)
salaries_df = pai.DataFrame(salaries_data)


pai.chat("Who gets paid the most?", employees_df, salaries_df)
Olivia gets paid the most.

Docker Sandbox

You can run PandasAI in a Docker sandbox, providing a secure, isolated environment to execute code safely and mitigate the risk of malicious attacks.

Python Requirements
pip install "pandasai-docker"
Usage
import pandasai as pai
from pandasai_docker import DockerSandbox
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
})

# Initialize the sandbox
sandbox = DockerSandbox()
sandbox.start()

employees_data = {
    'EmployeeID': [1, 2, 3, 4, 5],
    'Name': ['John', 'Emma', 'Liam', 'Olivia', 'William'],
    'Department': ['HR', 'Sales', 'IT', 'Marketing', 'Finance']
}

salaries_data = {
    'EmployeeID': [1, 2, 3, 4, 5],
    'Salary': [5000, 6000, 4500, 7000, 5500]
}

employees_df = pai.DataFrame(employees_data)
salaries_df = pai.DataFrame(salaries_data)

pai.chat("Who gets paid the most?", employees_df, salaries_df, sandbox=sandbox)

# Don't forget to stop the sandbox when done
sandbox.stop()
Olivia gets paid the most.

You can find more examples in the examples directory.

📜 License

PandasAI is available under the MIT expat license, except for the pandasai/ee directory of this repository, which has its license here.

If you are interested in managed PandasAI Cloud or self-hosted Enterprise Offering, contact us.

Resources

Beta Notice
Release v3 is currently in beta. The following documentation and examples reflect the features and functionality in progress and may change before the final release.

  • Docs for comprehensive documentation
  • Examples for example notebooks
  • Discord for discussion with the community and PandasAI team

🤝 Contributing

Contributions are welcome! Please check the outstanding issues and feel free to open a pull request. For more information, please check out the contributing guidelines.

Thank you!

Contributors

Core symbols most depended-on inside this repo

create
called by 41
pandasai/helpers/folder.py
build_query
called by 38
pandasai/query_builders/base_query_builder.py
apply_transformations
called by 31
pandasai/query_builders/sql_transformation_manager.py
log
called by 28
pandasai/helpers/logger.py
chat
called by 28
pandasai/agent/base.py
get_skills
called by 27
pandasai/config.py
get
called by 24
pandasai/config.py
load
called by 24
pandasai/helpers/filemanager.py

Shape

Method 1,084
Function 272
Class 176
Route 146

Languages

Python100%

Modules by API surface

tests/unit_tests/agent/test_agent.py55 symbols
tests/unit_tests/test_pandasai_init.py52 symbols
pandasai/exceptions.py35 symbols
extensions/ee/vectorstores/pinecone/tests/test_pinecone.py35 symbols
pandasai/query_builders/sql_transformation_manager.py34 symbols
tests/unit_tests/query_builders/test_sql_transformation_manager.py32 symbols
extensions/ee/vectorstores/chromadb/tests/test_chromadb.py31 symbols
tests/unit_tests/helpers/test_session.py30 symbols
tests/unit_tests/helpers/test_sql_sanitizer.py26 symbols
pandasai/smart_dataframe/__init__.py26 symbols
extensions/sandbox/docker/tests/test_sandbox.py26 symbols
tests/unit_tests/query_builders/test_query_builder.py25 symbols

For agents

$ claude mcp add pandas-ai \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact