Pandasai是一个Python平台,可以轻松以自然语言向您的数据提出问题。它可以帮助非技术用户以更自然的方式与数据进行交互,并帮助技术用户在处理数据时节省时间和精力。
?入门
您可以在此处找到Pandasai的完整文档。
您可以决定在Jupyter笔记本电脑,简化应用程序中使用Pandasai,也可以使用Repo中的客户端和服务器体系结构。
使用库
Python要求
Python版本3.8+ <3.12
?安装
您可以使用Pip或Poetry安装Pandasai库。
与pip:
pip install \" pandasai>=3.0.0b2 \"
诗歌:
poetry add \" pandasai>=3.0.0b2 \"
用法
问问题
import pandasai as pai from pandasai_openai . openai import OpenAI llm = OpenAI ( \"OPEN_AI_API_KEY\" ) pai . config . set ({ \"llm\" : llm }) # Sample DataFrame df = pai . DataFrame ({ \"country\" : [ \"United States\" , \"United Kingdom\" , \"France\" , \"Germany\" , \"Italy\" , \"Spain\" , \"Canada\" , \"Australia\" , \"Japan\" , \"China\" ], \"revenue\" : [ 5000 , 3200 , 2900 , 4100 , 2300 , 2100 , 2500 , 2600 , 4500 , 7000 ] }) df . chat ( \'Which are the top 5 countries by sales?\' )
China, United States, Japan, Germany, Australia
或者您可以提出更多复杂的问题:
df . chat ( \"What is the total sales for the top 3 countries by sales?\" )
The total sales for the top 3 countries by sales is 16500.
可视化图表
您也可以要求Pandasai为您生成图表:
df . chat ( \"Plot the histogram of countries showing for each one the gd. Use different colors for each bar\" , )
多个数据范围
您还可以将多个数据范围传递给Pandasai,并提出有关它们的问题。
import pandasai as pai from pandasai_openai . openai import OpenAI employees_data = { \'EmployeeID\' : [ 1 , 2 , 3 , 4 , 5 ], \'Name\' : [ \'John\' , \'Emma\' , \'Liam\' , \'Olivia\' , \'William\' ], \'Department\' : [ \'HR\' , \'Sales\' , \'IT\' , \'Marketing\' , \'Finance\' ] } salaries_data = { \'EmployeeID\' : [ 1 , 2 , 3 , 4 , 5 ], \'Salary\' : [ 5000 , 6000 , 4500 , 7000 , 5500 ] } llm = OpenAI ( \"OPEN_AI_API_KEY\" ) pai . config . set ({ \"llm\" : llm }) employees_df = pai . DataFrame ( employees_data ) salaries_df = pai . DataFrame ( salaries_data ) pai . chat ( \"Who gets paid the most?\" , employees_df , salaries_df )
Olivia gets paid the most.
Docker Sandbox
您可以在Docker Sandbox中运行Pandasai,提供一个安全的隔离环境,以安全地执行代码并减轻恶意攻击的风险。
Python要求
pip install \" pandasai-docker \"
用法
import pandasai as pai from pandasai_docker import DockerSandbox from pandasai_openai . openai import OpenAI # Initialize the sandbox sandbox = DockerSandbox () sandbox . start () employees_data = { \'EmployeeID\' : [ 1 , 2 , 3 , 4 , 5 ], \'Name\' : [ \'John\' , \'Emma\' , \'Liam\' , \'Olivia\' , \'William\' ], \'Department\' : [ \'HR\' , \'Sales\' , \'IT\' , \'Marketing\' , \'Finance\' ] } salaries_data = { \'EmployeeID\' : [ 1 , 2 , 3 , 4 , 5 ], \'Salary\' : [ 5000 , 6000 , 4500 , 7000 , 5500 ] } llm = OpenAI ( \"OPEN_AI_API_KEY\" ) pai . config . set ({ \"llm\" : llm }) employees_df = pai . DataFrame ( employees_data ) salaries_df = pai . DataFrame ( salaries_data ) pai . chat ( \"Who gets paid the most?\" , employees_df , salaries_df , sandbox = sandbox ) # Don\'t forget to stop the sandbox when done sandbox . stop ()
Olivia gets paid the most.
您可以在示例目录中找到更多示例。
执照
Pandasai可根据MIT外籍许可证获得,但该存储库的Pandasai/EE目录除外,该目录在此处具有其许可证。
如果您对托管Pandasai Cloud或自主企业提供感兴趣,请与我们联系。
资源
beta通知
版本V3目前正在Beta中。以下文档和示例反映了正在进行的功能和功能,并可能在最终版本之前发生变化。
- 综合文档的文档
- 示例示例笔记本
- 与社区和Pandasai团队讨论的不和谐
?贡献
欢迎捐款!请检查出色的问题,并随时打开拉动请求。有关更多信息,请查看贡献指南。
