Chat with your database (SQL, CSV, pandas, mongodb, noSQL, etc). PandasAI makes data analysis conversational using LLMs (GPT 3.5 / 4, Anthropic, VertexAI) and RAG.
Project description
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 gd. Use different colors for each bar",
)
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
- 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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pandasai-3.0.0.tar.gz.
File metadata
- Download URL: pandasai-3.0.0.tar.gz
- Upload date:
- Size: 55.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1bac4e98085dad4cc5072a86287143bccf7b651b8b0459a82bdc20a93f427c9
|
|
| MD5 |
e6b4c2480ee528f9c3974d8bd24a7736
|
|
| BLAKE2b-256 |
fb286e98c3c5ece389e223103efcc540708800e0db8c3764d38fb596dfd729fb
|
File details
Details for the file pandasai-3.0.0-py3-none-any.whl.
File metadata
- Download URL: pandasai-3.0.0-py3-none-any.whl
- Upload date:
- Size: 83.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.10.18 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d37629f2450dfe25b47b437f581ce7ca88c4ea321f9a9c8c1eaf4e82ed52ebf
|
|
| MD5 |
bbde9a93f8c4b40a87b084c86a62f222
|
|
| BLAKE2b-256 |
7acf1dba25c504810d946aacd6e4b2fb9c4a415a88d1850a8a4788a2c8599e24
|