Skip to main content
This documentation page is for backwards compatibility. For new projects, we recommend using the new semantic dataframes.

Migrate SmartDataframe

To migrate from SmartDataframe to the new semantic dataframes:
  1. Replace SmartDataframe imports with semantic dataframe imports
  2. Update configuration to use pai.config.set()
  3. Use the new .chat() method syntax
Example migration:
# Old code
from pandasai import SmartDataframe
smart_df = SmartDataframe(df)

# New code
import pandasai as pai

df = pai.DataFrame(df)

SmartDataframe (Legacy)

The SmartDataframe class was the previous way to create dataframes in PandasAI. It provided similar functionality to the current semantic dataframes but with a different API.

Basic Usage

from pandasai import SmartDataframe
import pandas as pd

# Create a pandas DataFrame
df = pd.DataFrame({
    'name': ['John', 'Emma', 'Alex', 'Sarah'],
    'age': [28, 24, 32, 27],
    'city': ['New York', 'London', 'Paris', 'Tokyo']
})

# Convert to SmartDataframe
smart_df = SmartDataframe(df)

# Ask questions about your data
response = smart_df.chat("What is the average age?")

Configuration

SmartDataframe accepted configuration options through its constructor:
smart_df = SmartDataframe(df, config={
    "llm": llm,                              # LLM instance
    "save_logs": True,                       # Save conversation logs
    "verbose": False                         # Print detailed logs
})
I