大家好
点击上方“萝卜大杂烩”,选择“星标”公众号
超级无敌干货,第一时间送达!!!
pandas是一个基于python和numpy的数据分析库,特别擅长数据处理和数据分析。
今年AI在大模型方面十分火热,尤其是ChatGPT等工具的出现,让我们的编程更加智(失)能(业)。
最近,就有一位大佬将pandas和AI强强联手,帮助我们更加快速便捷地分析数据。
目前已经4k多的点赞,GitHub项目地址:https://github.com/gventuri/pandas-ai
pandas-ai现身
Github官方解释什么是pandas-ai:
Pandas AI is a Python library that adds generative artificial intelligence capabilities to Pandas, the popular data analysis and manipulation tool. It is designed to be used in conjunction with Pandas, and is not a replacement for it.
pandas AI 是一个 Python 库,它为流行的数据分析和操作工具 Pandas 添加了生成人工智能功能。它旨在与 pandas 结合使用,而不是它的替代品。
安装十分简单:
pip install pandasai # 命令行
!pip install pandasai # jupyter notebook中使用
1、导入相关的库:
import pandas as pd
from pandasai import PandasAI
from pandasai.llm.openai import OpenAI2、模拟生成数据:
import pandas as pd
from pandasai import PandasAI
df = pd.DataFrame({
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
"gdp": [19294482071552, 2891615567872, 2411255037952, 3435817336832, 1745433788416, 1181205135360, 1607402389504, 1490967855104, 4380756541440, 14631844184064],
"happiness_index": [6.94, 7.16, 6.66, 7.07, 6.38, 6.4, 7.23, 7.22, 5.87, 5.12]
})3、初始化一个llm模型
from pandasai.llm.openai import OpenAI
llm = OpenAI()4、调用大模型实例,使用提示promote
pandas_ai = PandasAI(llm)
pandas_ai.run(df, prompt='Which are the 5 happiest countries?')显示结果为:
6 Canada
7 Australia
1 United Kingdom
3 Germany
0 United States
Name: country, dtype: object另一个实例:
pandas_ai.run(df, prompt='What is the sum of the GDPs of the 2 unhappiest countries?')
19012600725504绘图功能也是轻松搞定:
pandas_ai.run(
df,
"Plot the histogram of countries showing for each the gpd, using different colors for each bar",
)
感兴趣的朋友赶紧去试试!
原文始发于微信公众号(萝卜大杂烩):pandas-ai火了!
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论