| title | Quickstart |
|---|---|
| description | Start building your data preparation layer with PandasAI and chat with your data |
PandasAI requires Python 3.8+ <3.12. We recommend using Poetry for dependency management:
# Using poetry (recommended)
poetry add "pandasai>=3.0.0b2"
# Alternative: using pip
pip install "pandasai>=3.0.0b2"In order to use PandasAI, you need a large language model (LLM). While you can use any LLM, for the purpose of this guide, we are using BambooLLM. You can get your free API key signing up at app.pandabi.ai, which allows you to both use the data platform and get BambooLLM credits.
First, import PandasAI and set up your API key:
import pandasai as pai
# Get your API key from https://app.pandabi.ai
pai.api_key.set("YOUR_PANDABI_API_KEY")import pandasai as pai
# Load your data
df = pai.read_csv("data/companies.csv")
response = df.chat("What is the average revenue by region?")
print(response)When you ask a question, PandasAI will use the LLM to generate the answer and output a response. Depending on your question, it can return different kind of responses:
- string
- dataframe
- chart
- number
Find it more about output data formats here.
Start by creating a data schema that describes your dataset:
import pandasai as pai
# Load your data
df = pai.read_csv("data/companies.csv")
# Create the data layer
companies = pai.create(
path="my-org/companies",
df=df,
description="Customer companies dataset"
)This dataset will be saved in the datasets/my-org/companies folder of your project.
By default, the column will be inferred from the data. For more control, though, you can define explicit column schemas:
# Define a companies dataset with explicit schema
companies = pai.create(
path="my-org/companies",
df=df,
description="Customer companies dataset",
columns=[
{
"name": "company_name",
"type": "string",
"description": "The name of the company"
},
{
"name": "revenue",
"type": "float",
"description": "The revenue of the company"
},
{
"name": "region",
"type": "string",
"description": "The region of the company"
}
]
)Once defined, you can easily load and query your datasets:
# Load existing datasets
stocks = pai.load("organization/coca_cola_stock")
companies = pai.load("organization/companies")
# Query using natural language
response = stocks.chat("What is the volatility of the Coca Cola stock?")
response = companies.chat("What is the average revenue by region?")
# Query using multiple datasets
result = pai.chat("Compare the revenue between Coca Cola and Apple", stocks, companies)- Learn more about Semantic Layer
- Join our Discord Community for support {/* - Explore Advanced Views and Joins /} {/ - Check out our Example Projects */}