Python Pandas と同等の JavaScript 質問する

Python Pandas と同等の JavaScript 質問する

この CSV の例では、

   Source,col1,col2,col3
   foo,1,2,3
   bar,3,4,5

私が Pandas を使用する標準的な方法は次のとおりです。

  1. CSVを解析する

  2. データフレームに列を選択する(col1およびcol3

  3. 列を処理する(例:col1との値の平均をとるcol3

Pandas のようにそれを実行する JavaScript ライブラリはありますか?

ベストアンサー1

このウィキでは、多くのパンダのような JavaScript ライブラリを要約して比較します。

一般的に、d3 JavaScript ライブラリをチェックする必要があります。d3 は、Python で pandas が役立つのと同じように、JavaScript でデータを処理するための非常に便利な「スイス アーミー ナイフ」です。d3 が DataFrame/Pandas の代替品ではない場合でも (つまり、d3 には同じ API がなく、d3 には pandas の動作に一致するメソッドを持つSeries/DataFrameクラスがありません)、pandas のように d3 が頻繁に使用されているのを目にするかもしれません。

アハメドの回答ではd3の使い方が説明されているいくつかのDataFrame機能を実現するために、以下のライブラリのいくつかは次のようなものからインスピレーションを得ました。学習JsDatad3 と lodash を使用します。

DataFrame スタイルのデータ変換 (分割、結合、グループ化など) については、いくつかの JavaScript ライブラリの簡単なリストを以下に示します。

ライブラリは、次のようなさまざまな言語で記述されていることに注意してください。

  • ブラウザ互換、つまりクライアントサイドJavaScript
  • Node.js 別名サーバーサイド JavaScript
  • タイプスクリプト
  • 中には、WebAssembly にトランスパイルされた CPython を使用するものもあります (ただし、Node.js やブラウザで動作します)

...自分に合ったオプションを使用してください:

  • ピオディデブラウザサポートとNodejsサポート
    • 新しくて非常に強力な候補アハメド・ファシの回答
    • CPython と数値 Python エコシステムの大部分 (「NumPy、pandas、SciPy、Matplotlib、scikit-learn を含む」) の WebAssembly トランスパイル、「ブラウザと Node.js 用」
    • プロジェクトJupyterに深く関わる人々によって作られた
    • 見る含まれるパッケージのリスト
  • ダンフォ-jsbrowser-support AND NodeJS-support)
    • From Vignesh's answer

    • danfo (which is often imported and aliased as dfd); has a basic DataFrame-type data structure, with the ability to plot directly

    • Built by the team at Tensorflow: "One of the main goals of Danfo.js is to bring data processing, machine learning and AI tools to JavaScript developers. ... Open-source libraries like Numpy and Pandas..."

    • pandas is built on top of numpy; likewise danfo-js is built on tensorflow-js

    • please note danfo may not (yet?) support multi-column indexes

  • pandas-js
    • UPDATE The pandas-js repo has not been updated in awhile
    • From STEEL and Feras' answers
    • "pandas.js is an open source (experimental) library mimicking the Python pandas library. It relies on Immutable.js as the NumPy logical equivalent. The main data objects in pandas.js are, like in Python pandas, the Series and the DataFrame."
  • dataframe-js
    • "DataFrame-js provides an immutable data structure for javascript and datascience, the DataFrame, which allows to work on rows and columns with a sql and functional programming inspired api."
  • data-forge
  • jsdataframe
    • "Jsdataframe is a JavaScript data wrangling library inspired by data frame functionality in R and Python Pandas."
  • dataframe
    • "explore data by grouping and reducing."
  • SQL Frames
    • "DataFrames meet SQL, in the Browser"
    • "SQL Frames is a low code data management framework that can be directly embedded in the browser to provide rich data visualization and UX. Complex DataFrames can be composed using familiar SQL constructs. With its powerful built-in analytics engine, data sources can come in any shape, form and frequency and they can be analyzed directly within the browser. It allows scaling to big data backends by transpiling the composed DataFrame logic to SQL."
  • Jandas (browser- AND NodeJS-support; a new TypeScript library developed in 2023)
    • Indexing and query very similar to Pandas
    • Negative number and range indexing
    • Support DataFrame with zero rows/columns
    • Support index with duplicated values
    • iterrows, sort_values, groupby and element-wise operation

Then after coming to this question, checking other answers here and doing more searching, I found options like:

  • Apache Arrow in JS
    • Thanks to user Back2Basics suggestion:
    • "Apache Arrow is a columnar memory layout specification for encoding vectors and table-like containers of flat and nested data. Apache Arrow is the emerging standard for large in-memory columnar data (Spark, Pandas, Drill, Graphistry, ...)"
  • polars
  • Observable
    • At first glance, seems like a JS alternative to the IPython/Jupyter 「ノートブック」
    • Observable のページでは、「Web プラットフォーム」上の「リアクティブ プログラミング」、「コミュニティ」を約束しています。
    • 5分間の紹介を見るここ
  • ポータル(以前はrecline;からルーファスの答え
    • 古くなっている可能性があります:「DataFrame」APIは使用しません
    • 古くなっている可能性があります:代わりに、jQuery を必要としないがブラウザを必要とする「マルチビュー」(UI) API (jQuery/DOM モデルに類似) を強調します。その他の例
    • 古くなっている可能性があります:また、MVC風のアーキテクチャ; バックエンドのもの(データベース接続など)を含む
  • jsデータ
    • 本当にORM! たいていのそのモジュール異なるデータに対応するストレージ質問(js-data-mongodb、、js-data-redisjs-data-cloud-datastore、並べ替え、フィルタリングなど。
    • プラス面としては、Node.js で最優先で動作することです。「Node.js とブラウザで動作します。」
  • 味噌(もう一つの提案ルーファス
  • アラSQL
    • 「AlaSQL」は、リレーショナル データとスキーマレス データの両方に対するクエリ速度とデータ ソースの柔軟性に重点を置いた、Javascript 用のオープン ソース SQL データベースです。ブラウザー、Node.js、Cordova で動作します。
  • いくつかの思考実験:

上記の選択を検討する際に使用した基準は次のとおりです。

  • 一般的な基準
    • 言語 (NodeJS vs ブラウザ JS vs Typescript)
    • 依存関係(つまり、基礎となるライブラリ / AJAX / リモート API を使用している場合)
    • 積極的にサポートされています(アクティブなユーザーベース、アクティブなソースリポジトリなど)
    • JSライブラリのサイズ/速度
  • パンダの基準はR比較
    • パフォーマンス
    • 機能性/柔軟性
    • 使いやすさ
  • Pandas / Dataframe APIとの類似性
    • 特に彼らの主な特徴
    • データサイエンス重視
    • 組み込みの視覚化機能
    • Jupyter(インタラクティブノートブック)などの他のツールと組み合わせた統合の実証

おすすめ記事