Back to Pandas Ai

PandasAI Quickstart Guide

examples/quickstart.ipynb

3.0.01.3 KB
Original Source

PandasAI Quickstart Guide

This notebook demonstrates how to get started with PandasAI and how to use it to analyze data through natural language.

Set up LLM

Use pandasai_litellm to select the LLm of your choice and use PandasAI

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

Read CSV

For this example, we will use a small dataset of heart disease patients from Kaggle.

python
file_df = pai.read_csv("./data/heart.csv")

Chat with Your Data

You can ask questions about your data using natural language

python
response = file_df.chat("What is the correlation between age and cholesterol?")
print(response)

Create Dataset

To avoid to reading the csv again and again create dataset in PandasAI to reused. The path must be in format 'organization/dataset'.

python
dataset = pai.create(path="your-organization/heart",
    name="Heart",
    df = file_df,
    description="Heart Disease Dataset")

Load Dataset

After creation you load dataset anytime with the following code

python
dataset = pai.load("your-organization/heart")