Coder Social home page Coder Social logo

imnotdev25 / pandas-ai Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sinaptik-ai/pandas-ai

0.0 0.0 0.0 1.23 MB

Pandas AI is a Python library that integrates generative artificial intelligence capabilities into Pandas, allowing for advanced data analysis tasks such as data synthesis and augmentation.

License: MIT License

Python 100.00%

pandas-ai's Introduction

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.

PandasAI

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

You can find more examples in the examples directory.

Environment Variables

In order to set the API key for the LLM (HuggingFaceHub, 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_OPENAI_API_KEY")

# OpenAssistant
llm = OpenAssistant(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.

Todo

  • Add support for more LLMs
  • Make PandasAI available from a CLI
  • Create a web interface for PandasAI
  • Add CI/CD
  • Add support for conversational responses

pandas-ai's People

Contributors

gventuri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.