A wrapper around pandas to make it conversational
Project description
PandasAI 🐼
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.
Installation
pip install pandasai
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 back, in the form of Pandas DataFrames. For example, you can ask PandasAI to find all the rows in a DataFrame where the value of a column is greater than 5, and it will return a DataFrame containing only those rows:
import pandas as pd
from pandas_ai 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 llm.openai import OpenAI
llm = OpenAI()
pandas_ai = PandasAI(df, llm)
pandas_ai.run('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 ask PandasAI to perform more complex queries. For example, you can ask PandasAI to find the sum of the GDPs of the 2 unhappiest countries:
pandas_ai.run('What is the sum of the GDPs of the 2 unhappiest countries?')
The above code will return the following:
14516000
License
PandasAI is licensed under the MIT License. See the LICENSE file for more details.
Contributing
Contributions are welcome!
Todo
- Add support for more LLMs
- Add support for conversational responses
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.