Pandas AI: 强强联手,让数据分析更快速便捷

释放双眼,带上耳机,听听看~!
Pandas AI是一个Python库,为流行的数据分析和操作工具Pandas添加了生成人工智能功能,让数据分析更快速便捷。文章介绍了Pandas AI的安装和使用,并展示了如何使用Pandas AI进行数据分析。

公众号:尤而小屋
作者:Peter
编辑:Peter

大家好,我是Peter~

关注小屋的朋友肯定都知道小编一直在坚持写pandas相关的文章,最近的一篇请参考:

Pandas是一个基于python和numpy的数据分析库,特别擅长数据处理和数据分析。

今年AI在大模型方面十分火热,尤其是ChatGPT等工具的出现,让我们的编程更加智(失)能(业)。

最近,就有一位大佬将Pandas和AI强强联手,帮助我们更加快速便捷地分析数据。

GitHub项目地址:github.com/gventuri/pa…

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 OpenAI

2、模拟生成数据:

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",
)
本网站的内容主要来自互联网上的各种资源,仅供参考和信息分享之用,不代表本网站拥有相关版权或知识产权。如您认为内容侵犯您的权益,请联系我们,我们将尽快采取行动,包括删除或更正。
AI教程

能不能用 AI 编程辅助写代码?

2023-11-23 1:41:14

AI教程

Hugging Face中文博客正式上线,欢迎加入人工智能社区

2023-11-23 3:51:14

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索