Pandas AI is a Python library that adds generative artificial intelligence capabilities to the popular Python data analysis and manipulation tool, the Pandas library, and is intended to be used in conjunction with Pandas, not as a replacement for it.
demo
Try out PandasAI in your browser:
Install
usage
PandasAI is designed to be used in conjunction with Pandas. It makes Pandas conversational, allowing you to ask questions about your data and get answers, in the form of Pandas DataFrames.
For example, you can ask PandasAI to find all rows in a DataFrame with a column value greater than 5, and it will return a DataFrame containing only those rows:
import pandas as pd
from pandasai import PandasAI
# Sample DataFrame
df = pd.DataFrame({
"country": ["United States", "United Kingdom", "France", "Germany", "Italy", "Spain", "Canada", "Australia", "Japan", "China"],
"gdp": [21400000, 2940000, 2830000, 3870000, 2160000, 1350000, 1780000, 1320000, 516000, 14000000],
"happiness_index": [7.3, 7.2, 6.5, 7.0, 6.0, 6.3, 7.3, 7.3, 5.9, 5.0]
})
# Instantiate a LLM
from pandasai.llm.openai import OpenAI
llm = OpenAI()
pandas_ai = PandasAI(llm)
pandas_ai.run(df, prompt="Which are the 5 happiest countries?")
The above code will return the following:
0 United States
6 Canada
7 Australia
1 United Kingdom
3 Germany
Name: country, dtype: object
Of course, you can also let PandasAI do more complex queries. For example, you can ask PandasAI to find the sum of the GDPs of the 2 least happy countries:
pandas_ai.run(df, prompt="What is the sum of the GDPs of the 2 unhappiest countries?")
上面的代码将返回以下内容:
14516000
You can also ask PandasAI to draw:
pandas_ai.run(
df,
"Plot the histogram of countries showing for each the gpd, using different colors for each bar",
)
allowableexampleFind more examples in the table of contents.
#Pandas #Homepage #Documentation #Downloads #Adding #Functions #Pandas #Library #News Fast Delivery