Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

nodejs front-end of polars

License

NotificationsYou must be signed in to change notification settings

pola-rs/nodejs-polars

Repository files navigation

Polars: Blazingly fast DataFrames in Rust, Python, Node.js, R and SQL

rust docsBuild and testPyPI Latest ReleaseNPM Latest Release

Documentation:Node.js- Rust- Python- R|StackOverflow: Node.js- Rust- Python|User Guide|Discord

Note: This library is intended to work only with server side JS/TS (Node, Bun, Deno). For browser please seejs-polars

Usage

Importing

// esmimportplfrom'nodejs-polars';// requireconstpl=require('nodejs-polars');

Series

>constfooSeries=pl.Series("foo",[1,2,3])>fooSeries.sum()6// a lot operations support both positional and named arguments// you can see the full specs in the docs or the type definitions>fooSeries.sort(true)>fooSeries.sort({descending:true})shape:(3,)Series:'foo'[f64][321]>fooSeries.toArray()[1,2,3]// Series are 'Iterables' so you can use javascript iterable syntax on them>[...fooSeries][1,2,3]>fooSeries[0]1

DataFrame

>constdf=pl.DataFrame(...{...A:[1,2,3,4,5],...fruits:["banana","banana","apple","apple","banana"],...B:[5,4,3,2,1],...cars:["beetle","audi","beetle","beetle","beetle"],...}...)>df.sort("fruits").select(..."fruits",..."cars",...pl.lit("fruits").alias("literal_string_fruits"),...pl.col("B").filter(pl.col("cars").eq(pl.lit("beetle"))).sum(),...pl.col("A").filter(pl.col("B").gt(2)).sum().over("cars").alias("sum_A_by_cars"),...pl.col("A").sum().over("fruits").alias("sum_A_by_fruits"),...pl.col("A").reverse().over("fruits").flatten().alias("rev_A_by_fruits")...)shape:(5,8)┌──────────┬──────────┬──────────────┬─────┬─────────────┬─────────────┬─────────────┐fruitscarsliteral_striBsum_A_by_casum_A_by_frrev_A_by_fr------ng_fruits---rsuitsuitsstrstr---i64---------stri64i64i64╞══════════╪══════════╪══════════════╪═════╪═════════════╪═════════════╪═════════════╡"apple""beetle""fruits"11474├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤"apple""beetle""fruits"11473├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤"banana""beetle""fruits"11485├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤"banana""audi""fruits"11282├╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┤"banana""beetle""fruits"11481└──────────┴──────────┴──────────────┴─────┴─────────────┴─────────────┴─────────────┘
>df["cars"]// or df.getColumn("cars")shape:(5,)Series:'cars'[str]["beetle""beetle""beetle""audi""beetle"]

Node setup

Install the latest polars version with:

$ yarn add nodejs-polars# yarn$ npm i -s nodejs-polars# npm

Releases happen quite often (weekly / every few days) at the moment, so updating polars regularly to get the latest bugfixes / features might not be a bad idea.

Minimum Requirements

  • Node version>=18
  • Rust version>=1.59 -Only needed for development

Deno

In Deno modules you can import polars straight fromnpm:

importplfrom"npm:nodejs-polars";

With Deno 1.37, you can use thedisplay function to display aDataFrame in the notebook:

importplfrom"npm:nodejs-polars";import{display}from"https://deno.land/x/display@v1.1.1/mod.ts";letresponse=awaitfetch("https://cdn.jsdelivr.net/npm/world-atlas@1/world/110m.tsv",);letdata=awaitresponse.text();letdf=pl.readCSV(data,{sep:"\t"});awaitdisplay(df)

With Deno 1.38, you only have to make the dataframe be the last expression in the cell:

importplfrom"npm:nodejs-polars";letresponse=awaitfetch("https://cdn.jsdelivr.net/npm/world-atlas@1/world/110m.tsv",);letdata=awaitresponse.text();letdf=pl.readCSV(data,{sep:"\t"});df
image

Documentation

Want to know about all the features Polars supports? Read the docs!

Python

Rust

Node

Contribution

Want to contribute? Read ourcontribution guideline.

[Node]: compile polars from source

If you want a bleeding edge release or maximal performance you should compilepolars from source.

  1. Install the latestRust compiler
  2. Runnpm|yarn install
  3. Choose any of:
    • Fastest binary, very long compile times:
      $cd nodejs-polars&& yarn build&& yarn build:ts# this will generate a /bin directory with the compiles TS code, as well as the rust binary
    • Debugging, fastest compile times but slow & large binary:
      $cd nodejs-polars&& yarn build:debug&& yarn build:ts# this will generate a /bin directory with the compiles TS code, as well as the rust binary

Webpack configuration

To usenodejs-polars withWebpack please usenode-loader andwebpack.config.js

Acknowledgements

Development of Polars is proudly powered by

Xomnia

Sponsors


[8]ページ先頭

©2009-2025 Movatter.jp