ScriptsMar 31, 2026·2 min read

PandasAI — Chat with Your Data Using AI

Conversational data analysis with LLMs. Chat with SQL databases, CSV, Parquet files using natural language. Auto-generates Python/SQL and visualizations. 23K+ stars.

TL;DR
PandasAI lets you chat with SQL databases, CSV, and Parquet files using natural language queries.
§01

What it is

PandasAI is a Python library that adds conversational capabilities to data analysis. You ask questions about your data in natural language, and PandasAI generates the Python code or SQL query to answer them. It works with pandas DataFrames, SQL databases, CSV files, and Parquet files. It can also generate visualizations automatically.

PandasAI targets data analysts, scientists, and business users who want to explore datasets without writing code manually. It bridges the gap between natural language questions and programmatic data analysis.

§02

How it saves time or tokens

PandasAI eliminates the translation step between 'what do I want to know' and 'how do I write the code.' Instead of composing groupby, merge, and pivot operations manually, you describe what you need. The library generates and executes the code, returning results or charts. For exploratory analysis where you run dozens of ad-hoc queries, this reduces each query from minutes to seconds. Estimated token usage is around 500 tokens per query.

§03

How to use

  1. Install PandasAI:
pip install pandasai
  1. Create a SmartDataframe and ask questions:
import pandas as pd
from pandasai import SmartDataframe

df = pd.DataFrame({
    'country': ['USA', 'China', 'Japan', 'Germany', 'India'],
    'gdp': [21400, 14700, 5100, 3800, 2900],
    'population': [331, 1400, 126, 83, 1380]
})

sdf = SmartDataframe(df)
result = sdf.chat('Which country has the highest GDP per capita?')
print(result)
  1. Generate visualizations:
sdf.chat('Plot a bar chart of GDP by country')
# Generates and displays a matplotlib chart
§04

Example

Connecting to a SQL database:

from pandasai import SmartDataframe
from pandasai.connectors import PostgreSQLConnector

connector = PostgreSQLConnector(
    config={
        'host': 'localhost',
        'port': 5432,
        'database': 'analytics',
        'username': 'user',
        'password': 'pass',
        'table': 'sales'
    }
)

sdf = SmartDataframe(connector)
sdf.chat('What were the total sales by region last quarter?')
§05

Related on TokRepo

§06

Common pitfalls

  • PandasAI executes generated code automatically. Review the generated code before running on sensitive datasets, especially when connected to production databases.
  • Complex multi-step queries sometimes produce incorrect code. Break complex questions into simpler sub-questions for more reliable results.
  • LLM API costs accumulate during heavy exploratory sessions. Consider using local models via Ollama for high-volume analysis.

Frequently Asked Questions

Does PandasAI work with local LLMs?+

Yes. PandasAI supports Ollama and other local model providers. Configure the LLM parameter to point to your local endpoint, eliminating API costs for exploratory sessions.

Can PandasAI connect to SQL databases directly?+

Yes. PandasAI provides connectors for PostgreSQL, MySQL, and other databases. It generates SQL queries or loads data into DataFrames depending on the question complexity.

Is PandasAI safe for production data?+

PandasAI executes generated Python code, which carries risk. Use read-only database credentials and review generated code before execution. Do not point it at production databases without safeguards.

What types of visualizations can it create?+

PandasAI generates matplotlib and seaborn charts including bar charts, line plots, scatter plots, histograms, and pie charts. Specify the chart type in your natural language query.

How accurate are the generated queries?+

Accuracy depends on the LLM model used and the clarity of your question. Simple aggregations and filters are highly reliable. Complex joins or multi-step transformations may require iteration or manual correction.

Citations (3)
🙏

Source & Thanks

Created by Sinaptik AI. Licensed under custom license. Sinaptik-AI/pandas-ai — 23,000+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets