Tablecloth

repository·master·Indexed 18 days ago

https://github.com/scicloj/tablecloth

A Clojure library providing a high-level, thread-first API for dataset manipulation, designed to complement and extend the tech.ml.dataset library. Inspired by R solutions like dplyr, tidyr, and data.table, it offers a simplified API for common data tasks and supports polymorphic operations on both regular and grouped datasets.

Tokens
664
Snippets
1
Records
4
Agent score
13%

What's inside tablecloth

  1. Introduction to Tablecloth

    master

    Tablecloth is a dataset (data frame) manipulation API built on top of the tech.ml.dataset library. It provides a simplified, thread-first API for common data manipulation tasks, inspired by R solutions like dplyr, tidyr, and data.table.

    Key Features:

    • Simplified API: Focuses on dataset manipulation, leaving pipelines, datatypes, and ML to tech.ml.
    • Unified Entry Point: Uses a single function dispatching on arguments for common operations.
    • Grouped Datasets: group-by operations return a special kind of dataset containing subsets as a column. Most operations automatically recognize and process both regular and grouped datasets.
    • Thread-first Friendly: Designed to work seamlessly with Clojure's thread-first macro (->).

    Note: Tablecloth is an addition to tech.ml.dataset, not a replacement.

  2. How grouped datasets work in Tablecloth

    master

    When you use tc/group-by, the resulting dataset is a special kind of dataset that contains the subsets created during the grouping process as a column.

    Most Tablecloth operations are designed to be polymorphic: they recognize whether they are receiving a regular dataset or a grouped dataset and process the data accordingly. This allows you to chain operations like tc/aggregate or tc/order-by immediately after a grouping operation without manual subsetting.

  3. Basic Usage Example with tablecloth.api

    master

    To use Tablecloth, require tablecloth.api as tc. The following example demonstrates loading a CSV, grouping by symbol and year, aggregating the mean price, ordering the results, and taking the top 10 rows.

    (require '[tablecloth.api :as tc])
    
    (-> "https://raw.githubusercontent.com/techascent/tech.ml.dataset/master/test/data/stocks.csv"
        (tc/dataset {:key-fn keyword})
        (tc/group-by (fn [row]
                        {:symbol (:symbol row)
                         :year (tech.v3.datatype.datetime/long-temporal-field :years (:date row))}))
        (tc/aggregate #(tech.v3.datatype.functional/mean (% :price)))
        (tc/order-by [:symbol :year])
        (tc/head 10))