Get started with PandasAI by installing it and using the SmartDataframe class.
pandasai
, first install it:
Before installation, we recommend you create a virtual environment using your preferred choice of environment manager e.g Poetry, Pipenv, Conda, Virtualenv, Venv etc.
pandasai
does not include all the dependencies that it supports by default. You can install the extra dependencies by running the following command:
extra-dependency-name
with any of the following:
google-ai
: this extra dependency is required if you want to use Google PaLM as a language model.google-sheet
: this extra dependency is required if you want to use Google Sheets as a data source.excel
: this extra dependency is required if you want to use Excel files as a data source.modin
: this extra dependency is required if you want to use Modin dataframes as a data source.polars
: this extra dependency is required if you want to use Polars dataframes as a data source.langchain
: this extra dependency is required if you want to support the LangChain LLMs.numpy
: this extra dependency is required if you want to support numpy.ggplot
: this extra dependency is required if you want to support ggplot for plotting.seaborn
: this extra dependency is required if you want to support seaborn for plotting.plotly
: this extra dependency is required if you want to support plotly for plotting.statsmodels
: this extra dependency is required if you want to support statsmodels.scikit-learn
: this extra dependency is required if you want to support scikit-learn.streamlit
: this extra dependency is required if you want to support streamlit.ibm-watsonx-ai
: this extra dependency is required if you want to use IBM watsonx.ai as a language modelSmartDataframe
class is the main class of pandasai
. It is used to interact with a single dataframe. Below is a simple example to get started with pandasai
.
SmartDataframe
class, check out this video:
The API access to OPENAI is a paid service. You have to set up billing. Make sure you read the Pricing information before experimenting.
SmartDatalake
instead of a SmartDataframe
.
Similarly to a SmartDataframe
, you can instantiate a SmartDatalake
as follows:
SmartDataframe
or a SmartDatalake
can be used to answer a single query and are meant to be used in a single session and for exploratory data analysis, an agent can be used for multi-turn conversations.
To instantiate an agent, you can use the following code:
SmartDataframe
or a SmartDatalake
, an agent will keep track of the state of the conversation and will be able to answer multi-turn conversations. For example:
SmartDataframe
, you can either pass a config
object with specific settings upon instantiation or modify the pandasai.json
file in your project’s root. The latter serves as the default configuration but can be overridden by directly specifying settings in the config
object at creation. This approach ensures flexibility and precision in how PandasAI handles your data.
Settings:
llm
: the LLM to use. You can pass an instance of an LLM or the name of an LLM. You can use one of the LLMs supported. You can find more information about LLMs heresave_logs
: whether to save the logs of the LLM. Defaults to True
. You will find the logs in the pandasai.log
file in the root of your project.verbose
: whether to print the logs in the console as PandasAI is executed. Defaults to False
.save_charts
: whether to save the charts generated by PandasAI. Defaults to False
. You will find the charts in the root of your project or in the path specified by save_charts_path
.save_charts_path
: the path where to save the charts. Defaults to exports/charts/
. You can use this setting to override the default path.open_charts
: whether to open the chart during parsing of the response from the LLM. Defaults to True
. You can completely disable displaying of charts by setting this option to False
.enable_cache
: whether to enable caching. Defaults to True
. If set to True
, PandasAI will cache the results of the LLM to improve the response time. If set to False
, PandasAI will always call the LLM.max_retries
: the maximum number of retries to use when using the error correction framework. Defaults to 3
. You can use this setting to override the default number of retries.security
: The “security” parameter allows for three levels depending on specific use cases: “none,” “standard,” and “advanced.” “standard” and “advanced” are especially useful for detecting malicious intent from user queries and avoiding the execution of potentially harmful code. By default, the “security” is set to “standard.” The security check might introduce stricter rules that could flag benign queries as harmful. You can deactivate it in the configuration by setting “security” to “none.”