pandas-ai README

The project's README from github.com/sinaptik-ai/pandas-ai. As one markdown file: README.md.

PandasAI

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

PandasAI is a Python library 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
pip install pandasai-litellm

With poetry:

poetry add pandasai
poetry add pandasai-litellm

๐Ÿ’ป 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 gdp. 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

๐Ÿค 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

pandas-ai (sinaptik-ai/pandas-ai)

Searching Databaseโ€ฆ

23.9K ยทGitHub
What is this?PandasAI is a Python library that lets you ask questions about your data (SQL, CSV, parquet, dataframes) in plain natural language, powered by LLMs.
Is this a standalone app or a library I import into my code?It's a Python library you install with pip or poetry and import into your own scripts or notebooks.
How do I get started with it?Install via pip or poetry, then load your data and ask questions directly through the library's API; full docs and example notebooks are provided.
What Python version do I need?You need Python 3.8 up to 3.11.
Is running generated code against my data safe?PandasAI can execute LLM-generated code, so they offer a Docker sandbox option to isolate execution and reduce the risk of malicious code running against your real environment.
What's the licensing situation?The core library is MIT licensed, but the pandasai/ee (enterprise) directory has a separate license, and there's a paid managed Cloud/self-hosted Enterprise offering.
Can I query more than one dataframe at once?Yes, you can pass multiple dataframes to PandasAI and ask questions that relate them to each other.
Can it generate charts, not just text answers?Yes, you can ask PandasAI to generate charts directly from your data.
Is there a paid/hosted version?Yes, there's a managed PandasAI Cloud and a self-hosted Enterprise offering available by contacting the team.
Size
56.1 MB
Stars
23.9K
Age
3y
Commits ยท 90 Days