Accessing Polars from RUST
Remesh Govind N. M
V.P. Data Engineering | Certified Architect | Software Product/ Project Delivery,Big data, Web, Mobile applications, iOS , Android, Cloud, REST API
#Polars is a Rust-based data manipulation library that provides similar functionality as Pandas. It has support for loading and manipulating data from various sources, including CSV and Parquet files.
Pro Tip: If you want a quick introduction to Rust then look this up: RUST
CSV files are text files. With the bonus that Excel can read it in. We get this data often from public data such as form Kaggle, US FDA, data scrapped of a site or even world bank data .
Here's an example code snippet that demonstrates how to load data from both CSV and Parquet files using Polars DataFrame:
Read CSV with RUST
use polars::prelude::*;
fn main()
? ?// Load data from CSV file
? ?let csv_path = "path/to/csv/file.csv";
? ?let csv_df = CsvReader::from_path(csv_path)
? ? ? ?.unwrap()
? ? ? ?.finish()
? ? ? ?.unwrap();
? ?// Do something with the DataFrame
}
Read Parquet with RUST
use polars::prelude::*
fn main()
? ?
? ?// Load data from Parquet file
? ?let parquet_path = "path/to/parquet/file.parquet";
? ?let parquet_df = ParquetReader::try_from_file(parquet_path)
? ? ? ?.unwrap()
? ? ? ?.finish()
? ? ? ?.unwrap();
? ?// Do something with the DataFrame
};
In this snippet, we first load the data from a CSV file using the `CsvReader` provided by Polars. We specify the path to the file using `from_path()` method and then use `finish()` method to obtain a DataFrame containing the loaded data.
Next, we load the data from a Parquet file using `ParquetReader`. We again specify the path to the file using `try_from_file()` method followed by `finish()` method to obtain a DataFrame.
After loading both DataFrames, you can manipulate them as needed using various transformation methods provided by Polars.