langchain_experimental.agents.agent_toolkits.pandas.base
.create_pandas_dataframe_agent¶
- langchain_experimental.agents.agent_toolkits.pandas.base.create_pandas_dataframe_agent(llm: Runnable[Union[PromptValue, str, Sequence[Union[BaseMessage, List[str], Tuple[str, str], str, Dict[str, Any]]]], Union[BaseMessage, str]], df: Any, agent_type: Union[AgentType, Literal['openai-tools', 'tool-calling']] = AgentType.ZERO_SHOT_REACT_DESCRIPTION, callback_manager: Optional[BaseCallbackManager] = None, prefix: Optional[str] = None, suffix: Optional[str] = None, input_variables: Optional[List[str]] = None, verbose: bool = False, return_intermediate_steps: bool = False, max_iterations: Optional[int] = 15, max_execution_time: Optional[float] = None, early_stopping_method: str = 'force', agent_executor_kwargs: Optional[Dict[str, Any]] = None, include_df_in_prompt: Optional[bool] = True, number_of_head_rows: int = 5, extra_tools: Sequence[BaseTool] = (), engine: Literal['pandas', 'modin'] = 'pandas', **kwargs: Any) AgentExecutor [source]¶
Construct a Pandas agent from an LLM and dataframe(s).
- Parameters
llm (Runnable[Union[PromptValue, str, Sequence[Union[BaseMessage, List[str], Tuple[str, str], str, Dict[str, Any]]]], Union[BaseMessage, str]]) â Language model to use for the agent. If agent_type is âtool-callingâ then llm is expected to support tool calling.
df (Any) â Pandas dataframe or list of Pandas dataframes.
agent_type (Union[AgentType, Literal['openai-tools', 'tool-calling']]) â One of âtool-callingâ, âopenai-toolsâ, âopenai-functionsâ, or âzero-shot-react-descriptionâ. Defaults to âzero-shot-react-descriptionâ. âtool-callingâ is recommended over the legacy âopenai-toolsâ and âopenai-functionsâ types.
callback_manager (Optional[BaseCallbackManager]) â DEPRECATED. Pass âcallbacksâ key into âagent_executor_kwargsâ instead to pass constructor callbacks to AgentExecutor.
prefix (Optional[str]) â Prompt prefix string.
suffix (Optional[str]) â Prompt suffix string.
input_variables (Optional[List[str]]) â DEPRECATED. Input variables automatically inferred from constructed prompt.
verbose (bool) â AgentExecutor verbosity.
return_intermediate_steps (bool) â Passed to AgentExecutor init.
max_iterations (Optional[int]) â Passed to AgentExecutor init.
max_execution_time (Optional[float]) â Passed to AgentExecutor init.
early_stopping_method (str) â Passed to AgentExecutor init.
agent_executor_kwargs (Optional[Dict[str, Any]]) â Arbitrary additional AgentExecutor args.
include_df_in_prompt (Optional[bool]) â Whether to include the first number_of_head_rows in the prompt. Must be None if suffix is not None.
number_of_head_rows (int) â Number of initial rows to include in prompt if include_df_in_prompt is True.
extra_tools (Sequence[BaseTool]) â Additional tools to give to agent on top of a PythonAstREPLTool.
engine (Literal['pandas', 'modin']) â One of âmodinâ or âpandasâ. Defaults to âpandasâ.
**kwargs (Any) â DEPRECATED. Not used, kept for backwards compatibility.
- Returns
An AgentExecutor with the specified agent_type agent and access to a PythonAstREPLTool with the DataFrame(s) and any user-provided extra_tools.
- Return type
Example
from langchain_openai import ChatOpenAI from langchain_experimental.agents import create_pandas_dataframe_agent import pandas as pd df = pd.read_csv("titanic.csv") llm = ChatOpenAI(model="gpt-3.5-turbo", temperature=0) agent_executor = create_pandas_dataframe_agent( llm, df, agent_type="tool-calling", verbose=True )