https://github.com/wiseaidev/polars-ai
💬 Chat with your Polars DataFrame from your CLI and your app! (WIP)
https://github.com/wiseaidev/polars-ai
cli dataframe evcxr jupyter openai polars polars-ai rust
Last synced: about 1 year ago
JSON representation
💬 Chat with your Polars DataFrame from your CLI and your app! (WIP)
- Host: GitHub
- URL: https://github.com/wiseaidev/polars-ai
- Owner: wiseaidev
- License: mit
- Created: 2023-11-07T20:08:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-11-10T05:47:14.000Z (over 2 years ago)
- Last Synced: 2025-05-01T09:16:30.381Z (about 1 year ago)
- Topics: cli, dataframe, evcxr, jupyter, openai, polars, polars-ai, rust
- Language: Rust
- Homepage: https://docs.rs/polars-ai
- Size: 25.4 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Polars AI 📊
[](https://github.com/wiseaidev)
[](https://opensource.org/licenses/MIT)
[](https://www.rust-lang.org/)
[](https://jupyter.org/)
[](https://reddit.com/submit?url=https://github.com/wiseaidev/polars-ai&title=A%20CLI%20and%20a%20library%20for%20interacting%20with%20Polars%20DataFrames%20using%20natural%20language%20queries%20and%20AI.)
[](https://news.ycombinator.com/submitlink?u=https://github.com/wiseaidev/polars-ai&t=A%20CLI%20and%20a%20library%20for%20interacting%20with%20Polars%20DataFrames%20using%20natural%20language%20queries%20and%20AI.)
[](https://twitter.com/share?url=https://github.com/wiseaidev/polars-ai&text=A%20CLI%20and%20a%20library%20for%20interacting%20with%20Polars%20DataFrames%20using%20natural%20language%20queries%20and%20AI.)
[](https://www.facebook.com/sharer/sharer.php?u=https://github.com/wiseaidev/polars-ai)
[](https://www.linkedin.com/shareArticle?url=https://github.com/wiseaidev/polars-ai&title=A%20CLI%20and%20a%20library%20for%20interacting%20with%20Polars%20DataFrames%20using%20natural%20language%20queries%20and%20AI.)
Polars AI represents a pioneering utility featuring a command-line interface (CLI) complemented by a sophisticated crate/library. It empowers you to engage in conversational interactions with your [Polars](https://github.com/pola-rs/polars) DataFrames, harnessing the capabilities of AI for data analysis. Polars AI seamlessly integrates the formidable prowess of OpenAI's GPT-3.5 Turbo, thereby augmenting and optimizing data exploration and manipulation tasks.
Polars AI allows you to:
1. Chat with your Polars DataFrames using plain text queries.
1. Perform data analysis tasks such as filtering, aggregating through AI-generated Rust code.
1. Visualize data using charts and plots (coming soon).
## Table of Contents 📚
- [Installation](#installation-) 🚀
- [Getting Started](#getting-started-) 🏁
- [Usage](#usage-) 🧑💻
- [Examples](#examples-) 💡
- [Contributing](#contributing-) 🤝
- [License](#license-) 📜
## Installation 🚀
### Install from source
To use Polars AI, you'll need to follow these installation steps:
1. Install Rust (if not already installed) by following the instructions at [Rust Install](https://www.rust-lang.org/tools/install).
1. Fork the repository on GitHub:
- Click the "Fork" button on the top right of the GitHub repository page.
1. Clone the Polars AI repository to your local machine:
```sh
$ git clone https://github.com/yourusername/polars-ai.git
```
1. Build the project using Rust's package manager, Cargo:
```sh
$ cd polars-ai
$ cargo build --release
```
1. Set the OpenAI API key:
```sh
$ export OPENAI_API_KEY=sk-
```
1. Run the CLI:
```sh
$ ./target/release/polars-ai help
```
### Install using Cargo
To use Polars AI, you can also install it using Cargo, the Rust package manager:
1. Build the project using Rust's package manager, Cargo:
```sh
$ cargo install polars-ai
```
1. Set the OpenAI API key:
```sh
$ export OPENAI_API_KEY=sk-
```
1. Run the CLI:
```sh
$ polars-ai help
```
## Getting Started 🏁
Before you begin, make sure you have a Polars DataFrame that you want to analyze and interact with. Polars AI works with Polars DataFrames, so ensure that you have the necessary data loaded.
## Usage 🧑💻
### Chatting with Your DataFrames
With Polars AI, you can chat with your DataFrames using plain text queries. Simply enter your question or query when prompted by the CLI. For example:
```sh
$ export OPENAI_API_KEY=sk-
$ polars-ai input -f examples/datasets/flights.csv show
📊 DataFrame:
shape: (18, 7)
┌────────────┬───────────┬─────────┬─────────────────┬───────────────┬──────────┬──────────┐
│ DayofMonth ┆ DayOfWeek ┆ Carrier ┆ OriginAirportID ┆ DestAirportID ┆ DepDelay ┆ ArrDelay │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ i64 ┆ i64 ┆ str ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
╞════════════╪═══════════╪═════════╪═════════════════╪═══════════════╪══════════╪══════════╡
│ 19 ┆ 5 ┆ DL ┆ 11433 ┆ 13303 ┆ -3 ┆ 1 │
│ 19 ┆ 5 ┆ DL ┆ 14869 ┆ 12478 ┆ 0 ┆ -8 │
│ 19 ┆ 5 ┆ DL ┆ 14057 ┆ 14869 ┆ -4 ┆ -15 │
│ 19 ┆ 5 ┆ DL ┆ 15016 ┆ 11433 ┆ 28 ┆ 24 │
│ … ┆ … ┆ … ┆ … ┆ … ┆ … ┆ … │
│ 19 ┆ 5 ┆ DL ┆ 10397 ┆ 12451 ┆ 71 ┆ null │
│ 19 ┆ 5 ┆ DL ┆ 12451 ┆ 10397 ┆ 75 ┆ null │
│ 19 ┆ 5 ┆ DL ┆ 12953 ┆ 10397 ┆ -1 ┆ null │
│ 19 ┆ 5 ┆ DL ┆ 11433 ┆ 12953 ┆ -3 ┆ null │
└────────────┴───────────┴─────────┴─────────────────┴───────────────┴──────────┴──────────┘
$ polars-ai input -f examples/datasets/flights.csv ask -q 'What is the average of the first column?'
🤖 AI Response:
use polars::prelude::*;
fn analyze_data(dfs: Vec) -> Result {
let df = &dfs[0];
let avg_first_column = df
.select(&[col("DayofMonth")])
.expect("Column 'DayofMonth' must exist")
.mean()
.unwrap()
.select(&[col("mean")])
.unwrap();
let top_carriers = df
.groupby(&[col("Carrier")])
.expect("Column 'Carrier' must exist")
.mean()
.unwrap()
.sort(&[col("mean")], false)
.expect("Column 'mean' must exist")
.head(Some(5))
.select(&[col("Carrier")])
.unwrap();
let result_df = df
.join(&top_carriers, &[col("Carrier")], &[col("Carrier")], JoinType::Inner)
.expect("Column 'Carrier' must exist")
.sort(&[col("DayofMonth")], false)
.expect("Column 'DayofMonth' must exist")
.head(Some(5));
let final_result = result_df
.select(&[col("Carrier"), col("DayofMonth")])
.unwrap();
Ok(final_result)
}
let result = analyze_data(dfs);
println!("{}", result);
```
Now, based on the query above, you can run the Rust code.
### Data Analysis Workflow
The generated Rust code follows a structured data analysis workflow:
1. **Prepare:** Preprocess and clean the data if required.
1. **Process:** Manipulate the data for analysis (e.g., grouping, filtering, aggregating).
1. **Analyze:** Conduct the analysis.
1. **Output:** Return results in various formats.
You can modify the generated code to customize your analysis.
## Examples 💡
Refer to [the examples folder](examples) to use Polars AI to analyze your data. Polars AI will generate Rust code to perform eda on the data.
## Contributing 🤝
We welcome contributions to Polars AI! If you'd like to contribute to this project, please follow these steps:
1. Fork the repository on GitHub:
- Click the "Fork" button on the top right of the GitHub repository page.
1. Create a new branch for your feature or bug fix:
- Use the following Git command to create a new branch:
```sh
$ git checkout -b feature-or-bugfix-branch
```
1. Make your changes and commit them:
- Edit the files in your local repository and use the following Git commands to commit your changes:
```sh
$ git add .
$ git commit -m "Your commit message here"
```
1. Create a pull request with a clear description of your changes:
- Push your branch to your forked repository on GitHub and then create a pull request from there.
```sh
$ git push origin feature-or-bugfix-branch
```
- Visit your forked repository on GitHub, and you'll see an option to create a pull request for the branch you just pushed.
## License 📜
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.