{"id":9167,"library":"pandasai","title":"PandasAI","description":"PandasAI is a Python library that enhances data analysis by integrating Large Language Models (LLMs) with pandas DataFrames. It allows users to interact with their data using natural language prompts, supporting various data sources like SQL, CSV, and Excel. Currently at version 3.0.0, the library is actively developed with a frequent release cadence, often introducing alpha and beta versions before stable releases.","status":"active","version":"3.0.0","language":"en","source_language":"en","source_url":"https://github.com/sinaptik-ai/pandas-ai","tags":["LLM","Data Analysis","Pandas","AI","Conversational AI","Generative AI","DataFrame"],"install":[{"cmd":"pip install pandasai pandasai-litellm","lang":"bash","label":"Core library with LiteLLM for LLM integration"},{"cmd":"pip install 'pandasai[excel]' 'pandasai[google-ai]' 'pandasai[sql][postgres]'","lang":"bash","label":"With optional data source and LLM dependencies"}],"dependencies":[{"reason":"Required Python version range.","package":"python","optional":false},{"reason":"Core data manipulation library; PandasAI is built on top of it.","package":"pandas","optional":false},{"reason":"Recommended extension for unified LLM access (e.g., OpenAI, Google PaLM, Anthropic, VertexAI) in v3.","package":"pandasai-litellm","optional":true},{"reason":"Needed for direct OpenAI LLM integration (older v2 pattern or if not using LiteLLM).","package":"openai","optional":true}],"imports":[{"note":"For PandasAI v3, `pandasai` should be imported as `pai` and its functions like `pai.DataFrame` or `pai.Agent` should be used. `PandasAI` class from v2 is deprecated.","wrong":"from pandasai import PandasAI","symbol":"pai","correct":"import pandasai as pai"},{"note":"In v3, LLMs are extension-based. LiteLLM is the recommended unified interface. Direct LLM imports like `pandasai.llm.openai.OpenAI` from v2 no longer work.","wrong":"from pandasai.llm.openai import OpenAI","symbol":"LiteLLM","correct":"from pandasai_litellm.litellm import LiteLLM"}],"quickstart":{"code":"import os\nimport pandas as pd\nimport pandasai as pai\nfrom pandasai_litellm.litellm import LiteLLM\n\n# Set your API key from environment variable\nopenai_api_key = os.environ.get('OPENAI_API_KEY', 'YOUR_OPENAI_API_KEY')\n\n# Initialize LiteLLM with your desired model\n# Ensure the model name is correct and supported by your LiteLLM setup/API key\nllm = LiteLLM(model=\"gpt-4o-mini\", api_key=openai_api_key)\n\n# Configure PandasAI globally with the LLM\npai.config.set({\"llm\": llm})\n\n# Sample DataFrame\ndata = {\n    \"country\": [\"United States\", \"United Kingdom\", \"France\", \"Germany\", \"Italy\", \"Spain\"],\n    \"gdp\": [19294482071552, 2891615567872, 2411255037952, 3435817336832, 1745433788416, 1181205135360],\n    \"happiness_index\": [6.94, 7.16, 6.66, 7.07, 6.38, 6.4]\n}\ndf = pd.DataFrame(data)\n\n# Convert pandas DataFrame to PandasAI DataFrame\npai_df = pai.DataFrame(df)\n\n# Chat with your data\nresponse = pai_df.chat(\"Which are the top 3 countries by GDP?\")\nprint(response)","lang":"python","description":"This quickstart demonstrates how to initialize PandasAI v3 with LiteLLM for conversational data analysis on a pandas DataFrame. It includes setting up the LLM globally and using the `pai.DataFrame` wrapper to query data in natural language."},"warnings":[{"fix":"Install `pandasai-litellm` and update LLM import paths. Use `pai.config.set({'llm': your_llm_instance})` for global LLM configuration. Refer to the official migration guide for v2 to v3.","message":"PandasAI v3 introduces significant architectural changes, particularly in how LLMs are configured and imported. LLMs are now extension-based, requiring separate installations like `pandasai-litellm`. The LLM must be configured globally using `pai.config.set()` instead of being passed directly to `SmartDataframe` or `Agent` constructors.","severity":"breaking","affected_versions":"3.0.0-alpha to 3.x.x (from v2.x.x)"},{"fix":"Migrate to `pai.DataFrame()` for single dataframes and use `pai.chat()` directly for multiple dataframes. Avoid using `push()` or `pull()` methods.","message":"The `SmartDataframe` and `SmartDatalake` classes from v2 are largely superseded by a new API pattern in v3. While `SmartDataframe` may still work for single dataframes, the recommended approach is `pai.DataFrame()`. `SmartDatalake` is no longer necessary, as `pai.chat()` can query multiple dataframes directly. Also, methods like `push()` and `pull()` on DataFrames were removed in v3.0.0.","severity":"breaking","affected_versions":"3.0.0-alpha to 3.x.x (from v2.x.x)"},{"fix":"These methods no longer exist. For conversational flow, rely on the `agent.chat()` and `agent.follow_up()` methods, which maintain context automatically.","message":"Several utility methods on the `Agent` class, such as `clarification_questions()`, `rephrase_query()`, and `explain()`, have been removed in v3.","severity":"breaking","affected_versions":"3.0.0-alpha to 3.x.x (from v2.x.x)"},{"fix":"Use a Python environment with version 3.8 to 3.11. If encountering build errors, consider installing `pandas==1.5.3` manually before installing `pandasai`, or use `conda install pandas=1.5.3` if in a Conda environment. Avoid using Pandas 3.0+ with current PandasAI versions.","message":"PandasAI currently specifies Python requirements as `<3.12,>=3.8` and may pin `pandas==1.5.3`. This can lead to installation failures or unexpected behavior if attempting to install with Python 3.12+ or if another package in your environment requires a newer `pandas` version (e.g., Pandas 3.0+ has significant breaking changes like Copy-on-Write semantics and dedicated string dtypes, which are incompatible with `pandasai`'s pinned version).","severity":"gotcha","affected_versions":"All versions up to 3.0.0"},{"fix":"Use explicit type hints in your prompts to guide the LLM. Implement a code validation layer before execution if possible. Consider pinning specific LLM model versions where supported. Log the generated Python code to identify failure patterns.","message":"LLM model drift (changes in underlying LLM behavior over time) can cause previously working queries to fail or produce incorrect Python code (e.g., type mismatches, inappropriate method calls) during execution by PandasAI. This is particularly noted with OpenAI models.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Install the appropriate LLM extension (e.g., `pip install pandasai-litellm`) and update imports (e.g., `from pandasai_litellm.litellm import LiteLLM`).","cause":"In PandasAI v3, LLM classes are no longer directly under `pandasai.llm` but are moved to separate extension packages.","error":"ModuleNotFoundError: No module named 'pandasai.llm'"},{"fix":"These methods are deprecated. Use `agent.chat()` for general interaction and `agent.follow_up()` to maintain conversational context.","cause":"The `clarification_questions`, `rephrase_query`, and `explain` methods on the `Agent` class were removed in PandasAI v3.","error":"AttributeError: 'Agent' object has no attribute 'clarification_questions'"},{"fix":"Verify the exact model name with your LLM provider and the `pandasai-litellm` documentation. Ensure your API key has the necessary permissions. Update `pandasai-litellm` to the latest version to support newer models.","cause":"The specified LLM model name is either incorrect, misspelled, not yet supported by the PandasAI LLM wrapper (e.g., LiteLLM), or your API key does not have access to it.","error":"UnsupportedModelError: Unsupported model: The model 'GPT-4o' doesn't exist or is not supported yet."},{"fix":"Be more explicit in your natural language prompts about expected data types (e.g., 'calculate the average of the numerical 'sales' column'). Consider pre-processing your DataFrame to ensure correct dtypes or implement explicit type casting in PandasAI 'skills' or `custom_instructions`.","cause":"The LLM generated Python code that attempts an operation (e.g., arithmetic) on columns with incompatible data types (e.g., trying to divide a string column by an integer). This can happen due to LLM misinterpretation of data or model drift.","error":"TypeError: unsupported operand type(s) for /: 'str' and 'int' (or similar type conversion errors during code execution)"}]}