docs/v3/migration-backwards-compatibility.mdx
SmartDataframe continues to work in v3 with the same API. However, you must configure the LLM globally.
from pandasai import SmartDataframe
import pandasai as pai
import pandas as pd
from pandasai_litellm.litellm import LiteLLM
# Configure LLM globally (required)
llm = LiteLLM(model="gpt-4o-mini", api_key="your-api-key")
pai.config.set({"llm": llm})
# v2 style still works
df = pd.DataFrame({
"country": ["US", "UK", "France"],
"sales": [5000, 3200, 2900]
})
smart_df = SmartDataframe(df)
response = smart_df.chat("What are the top countries by sales?")
While SmartDataframe works, we recommend using pai.DataFrame() for better integration with v3 features:
import pandasai as pai
import pandas as pd
# Configure LLM globally
pai.config.set({"llm": llm})
# Simple approach
df = pd.DataFrame({
"country": ["US", "UK", "France"],
"sales": [5000, 3200, 2900]
})
df = pai.DataFrame(df)
response = df.chat("What are the top countries by sales?")
Benefits of pai.DataFrame():
SmartDatalake still works but is no longer necessary. You can query multiple dataframes directly with pai.chat().
from pandasai import SmartDatalake
import pandasai as pai
import pandas as pd
from pandasai_litellm.litellm import LiteLLM
# Configure LLM globally (required)
llm = LiteLLM(model="gpt-4o-mini", api_key="your-api-key")
pai.config.set({"llm": llm})
# v2 style still works
employees_df = pd.DataFrame({
"name": ["John", "Jane", "Bob"],
"department": ["Sales", "Engineering", "Sales"]
})
salaries_df = pd.DataFrame({
"name": ["John", "Jane", "Bob"],
"salary": [60000, 80000, 55000]
})
lake = SmartDatalake([
employees_df,
salaries_df
])
response = lake.chat("Who gets paid the most?")
Query multiple dataframes directly without SmartDatalake:
import pandasai as pai
# Configure LLM globally
pai.config.set({"llm": llm})
# Create dataframes
employees = pai.DataFrame(employees_df)
salaries = pai.DataFrame(salaries_df)
# Query across multiple dataframes directly
response = pai.chat("Who gets paid the most?", employees, salaries)
Benefits of pai.chat():
SmartDatalakeThe Agent class works mostly the same way in v3 as it did in v2, but some methods have been removed. The main requirement is to configure the LLM globally.
from pandasai import Agent
import pandasai as pai
from pandasai_litellm.litellm import LiteLLM
# Configure LLM globally (required in v3)
llm = LiteLLM(model="gpt-4o-mini", api_key="your-api-key")
pai.config.set({"llm": llm})
# Agent works as before
df1 = pai.DataFrame(sales_data)
df2 = pai.DataFrame(costs_data)
agent = Agent([df1, df2])
response = agent.chat("Analyze the data and provide insights")
Key Change: Configure LLM globally with pai.config.set() instead of passing it per-agent.
PandasAI v3 introduces new Agent methods that enhance conversational capabilities:
follow_up(query): Continue conversations without clearing memory (maintains context)agent = Agent([df1, df2])
# Start conversation
response = agent.chat('What is the total revenue?')
# Follow up without losing context
follow_up = agent.follow_up('What about last quarter?')
Note: The clarification_questions(), explain() and rephrase_query() methods have been removed in v3.
These methods provide enhanced conversational capabilities not available in v2.
For detailed information about Agent usage, see the Agent documentation. For information about using Skills with Agent, see the Skills documentation.