Skip to main content

Pandas AI is a Python library that integrates generative artificial intelligence capabilities into Pandas, making dataframes conversational.

Project description

PandasAI 🐼

release lint lint Downloads License: MIT Open in Colab

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.

PandasAI

Demo

Try out PandasAI in your browser:

Open in Colab

Installation

pip install pandasai

Usage

Disclaimer: GDP data was collected from this source, published by World Development Indicators - World Bank (2022.05.26) and collected at National accounts data - World Bank / OECD. It relates to the year of 2020. Happiness indexes were extracted from the World Happiness Report. Another useful link.

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 pandasai import PandasAI

# Sample DataFrame
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]
})

# Instantiate a LLM
from pandasai.llm.openai import OpenAI
llm = OpenAI(api_token="YOUR_API_TOKEN")

pandas_ai = PandasAI(llm, conversational=False)
pandas_ai.run(df, prompt='Which are the 5 happiest countries?')

The above code will return the following:

6            Canada
7         Australia
1    United Kingdom
3           Germany
0     United States
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(df, prompt='What is the sum of the GDPs of the 2 unhappiest countries?')

The above code will return the following:

19012600725504

You can also ask PandasAI to draw a graph:

pandas_ai.run(
    df,
    "Plot the histogram of countries showing for each the gpd, using different colors for each bar",
)

Chart

You can find more examples in the examples directory.

Privacy & Security

In order to generate the Python code to run, we take the dataframe head, we randomize it (using random generation for sensitive data and shuffling for non-sensitive data) and send just the head.

Also, if you want to enforce further your privacy you can instantiate PandasAI with enforce_privacy = True which will not send the head (but just column names) to the LLM.

Environment Variables

In order to set the API key for the LLM (Hugging Face Hub, OpenAI), you need to set the appropriate environment variables. You can do this by copying the .env.example file to .env:

cp .env.example .env

Then, edit the .env file and set the appropriate values.

As an alternative, you can also pass the environment variables directly to the constructor of the LLM:

# OpenAI
llm = OpenAI(api_token="YOUR_API_KEY")

# Starcoder
llm = Starcoder(api_token="YOUR_HF_API_KEY")

License

PandasAI is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please check out the todos below, and feel free to open a pull request. For more information, please see the contributing guidelines.

After installing the virtual environment, please remember to install pre-commit to be compliant with our standards:

pre-commit install

Todo

  • Add support for more LLMs
  • Make PandasAI available from a CLI
  • Create a web interface for PandasAI
  • Add unit tests
  • Add contributing guidelines
  • Add CI
  • 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.

Source Distribution

pandasai-0.2.12.tar.gz (15.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandasai-0.2.12-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file pandasai-0.2.12.tar.gz.

File metadata

  • Download URL: pandasai-0.2.12.tar.gz
  • Upload date:
  • Size: 15.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.16 Darwin/21.6.0

File hashes

Hashes for pandasai-0.2.12.tar.gz
Algorithm Hash digest
SHA256 130853bca19e24f98935985cf34a77b4a7942a7f21fc2bcd52ee0cf1c9c3dfee
MD5 ca58eb3ffe5ce9bb458cf9e30da452be
BLAKE2b-256 a5b6f5a9329a56e42441dc4a045e9213ef74f80581233611e4e29e614c6409c2

See more details on using hashes here.

File details

Details for the file pandasai-0.2.12-py3-none-any.whl.

File metadata

  • Download URL: pandasai-0.2.12-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.9.16 Darwin/21.6.0

File hashes

Hashes for pandasai-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 092ff6735ea67bf81458112f21a79b478b2e2800a7b192431569a5e94d08c2bb
MD5 c6c4b7c67cbf2d7ed9bb8612ba794d75
BLAKE2b-256 f4273af9c94cde8792240e5f80bc7db119b0eae211b8f19ea9803724df163a5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page