说明:

使用 agno 库和 PandasTools 实现了一个 AI Agent,用于自动化数据分析。

该 Agent 加载 CSV 文件 (data.csv) 并根据自然语言指令执行分析。

能够在无需手动编写 Pandas 代码的情况下与数据进行交互,简化了数据探索和洞察提取的过程。

包含环境设置和依赖项的安装说明。


title: Pandas 工具

代码

cookbook/tools/pandas_tools.py
from agno.agent import Agent
from agno.tools.pandas import PandasTools

agent = Agent(
    tools=[PandasTools()],
    show_tool_calls=True,
    markdown=True,
)
agent.print_response("Load and analyze the dataset from data.csv")

用法

1

创建虚拟环境

打开 Terminal 并创建一个 python 虚拟环境。

python3 -m venv .venv
source .venv/bin/activate
2

设置您的 API 密钥

export OPENAI_API_KEY=xxx
3

安装库

pip install -U pandas openai agno
4

运行 Agent

python cookbook/tools/pandas_tools.py