AI Made Easy: pandasAI, insert chatGPT wings on pandas

Pandas AI is a Python library that enhances the widely used data analysis and processing tool Pandas by integrating generative artificial intelligence capabilities. It is designed to work with Pandas, not replace Pandas.

To install this package, you need to have python 3.9 or higher installed.

pip install pandasai

PandasAI is designed for use with Pandas, providing the library with conversational capabilities. It enables you to query data and get the response back as a Pandas DataFrame. For example, you can use PandasAI to find all rows in a DataFrame where a column value exceeds 5 and return a DataFrame containing only those rows.

import pandas as pd
from pandasai import PandasAI

# 示例DataFrame
df = pd.DataFrame({
    "country": ["美国", "英国", "法国", "德国", "意大利", "西班牙", "加拿大", "澳大利亚", "日本", "中国"],
    "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]
})

# 实例化LLM
from pandasai.llm.openai import OpenAI
llm = OpenAI(api_token="YOUR_API_TOKEN")

pandas_ai = PandasAI(llm, conversational=False)
pandas_ai(df, prompt='哪些国家是最幸福的5个国家?')

The output should look like this:

6            加拿大
7         澳大利亚
1            英国
3            德国
0            美国
Name: country, dtype: object

Another cool feature is plotting:

pandas_ai(
    df,
    "绘制每个国家的GDP直方图,使用不同颜色表示每个柱状条",
)

The result looks like this:

insert image description here

English version

English link

focus on

No public

Supongo que te gusta

Origin blog.csdn.net/robot_learner/article/details/130818454
Recomendado
Clasificación