kiwis-no-fs

0.0.2 • Public • Published

Kiwis 🥝

A Pandas-inspired data wrangling toolkit in JavaScript

Installation

npm install kiwis

Getting started

const kw = require('kiwis');
 
const h2g2Characters = kw.DataFrame([
    {
        name: 'Marvin',
        surname: '',
        occupation: 'Paranoid Android'
    },
    {
        name: 'Zaphod',
        surname: 'Beeblebrox',
        occupation: 'President of the Galaxy'
    },
    {
        name: 'Arthur',
        surname: 'Dent',
        occupation: null
    }
]);
 
h2g2Characters.show();
 
/*
|   name |    surname |              occupation
=================================================
0 | Marvin |        N/A |        Paranoid Android
1 | Zaphod | Beeblebrox | President of the Galaxy
2 | Arthur |       Dent |                     N/A
 
[3 rows × 3 columns]
Columns: name, surname, occupation
*/
 
console.log(h2g2Characters.get(1));
 
/*
{
    name: 'Zaphod',
    surname: 'Beeblebrox',
    occupation: 'President of the Galaxy'
}
*/
 
h2g2Characters.name.show();
 
/*
0 | Marvin
1 | Zaphod
2 | Arthur
 
Length: 3
*/

Documentation

Table of Contents

DataFrame

Properties

  • length number The number of rows in the DataFrame
  • empty boolean Whether the DataFrame contains any row or not
  • columns Array<string> The columns of the DataFrame

toArray

Returns the DataFrame as an array

Returns Array<Object>

clone

Clones the DataFrame

Returns DataFrame

get

Returns any row of the DataFrame

Parameters

Returns Object

first

Returns the first row of the DataFrame

Returns Object

last

Returns the last row of the DataFrame

Returns Object

head

Returns a new DataFrame containing the first N rows of the DataFrame

Parameters
  • n number Number of rows to select (optional, default 5)

Returns DataFrame

tail

Returns a new DataFrame containing the last N rows of the DataFrame

Parameters
  • n number Number of rows to select (optional, default 5)

Returns DataFrame

slice

Returns a new DataFrame with a slice of the original rows

Parameters
  • start number Zero-based index at which to start extraction
  • end number Zero-based index before which to end extraction (optional, default DataFrame.length)

Returns DataFrame

rows

Returns the rows of the DataFrame as an iterable

Returns Iterable<Object>

items

Returns an array of index/row pairs as an iterable

Returns Iterable<Array<number, Object>>

forEach

Applies a callback function to each row of the DataFrame

Parameters
  • callback callback

map

Returns a new Series populated with the results of a callback function applied on each row the DataFrame

Parameters
  • callback callback

Returns Series

replace

Replaces all occurences of the given value in the DataFrame by another value

Parameters
  • oldValue any
  • newValue any
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)
    • options.columns (string | Array<string>) Columns to replace into (optional, default DataFrame.columns)

append

Appends new rows to a DataFrame

Parameters
  • rows (Object | Array<Object>) Row or array of rows to append to the DataFrame
  • options Object? (optional, default {})
    • options.extend boolean Add new columns to the DataFrame if they do not already exist (optional, default false)

Returns DataFrame

insert

Inserts new rows into a DataFrame

Parameters
  • rows (Object | Array<Object>) Row or array of rows to insert into the DataFrame
  • index number Index to insert the rows at (optional, default 0)
  • options Object? (optional, default {})
    • options.extend boolean Add new columns to the DataFrame if they do not already exist (optional, default false)

Returns DataFrame

concat

Concats another DataFrame to the DataFrame

Parameters
  • other DataFrame
  • options Object? (optional, default {})
    • options.extend boolean Add new columns to the DataFrame if they do not already exist (optional, default false)
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

dropNA

Drops N/A values from the DataFrame

Parameters
  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether rows or columns should be dropped (optional, default 'rows')
    • options.keep Array<any> Array of falsy values to keep in the DataFrame (optional, default [0,false])
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

dropDuplicates

Drops duplicate rows from the DataFrame

Parameters
  • options Object? (optional, default {})
    • options.columns Array<string> Array of columns to consider for comparison (optional, default DataFrame.columns)
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

addColumn

Add a new column to the DataFrame

Parameters
  • name string Name of the new column
  • column (any | Array<any> | Series) Content of the new column as an array, a Series or any value (to be set on every rows)
  • options Object? (optional, default {})
    • options.extend boolean If the new column is not the same length as the DataFrame, extends the DataFrame (optional, default false)
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

rename

Rename columns of the DataFrame

Parameters
  • map Object<key, string> Map of the columns to rename to their new names
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

reorder

Reorder the columns of the DataFrame

Parameters
  • names Array<string> Array containing the new order of the columns
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

filter

Filters columns or rows of the DataFrame

Parameters
  • filter (callback | Array<string>) Can be a callback (applied to rows or columns) or an array of column names to keep
  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether the callback should apply to rows or columns (optional, default 'rows')
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

drop

Drops columns or rows from the DataFrame

Parameters
  • filter (callback | Array<string>) Can be a callback (applied to rows or columns) or an array of column names to drop
  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether the callback should apply to rows or columns (optional, default 'rows')
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

sort

Sorts the DataFrame

Parameters
  • by (string | Array<string>) Key or array of keys to sort the DataFrame by
  • options Object? (optional, default {})
    • options.reverse boolean Sorts the DataFrame in descending order (optional, default false)
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

shuffle

Shuffles the rows or columns of a DataFrame

Parameters
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)
    • options.axis ("rows" | "columns") Determines whether rows or columns should be shuffled (optional, default 'rows')

Returns DataFrame

pivot

Returns a PivotTable along the given columns

Parameters

Returns PivotTable

toString

Format the DataFrame for display

Returns string

show

Displays the DataFrame

toCSV

Exports the DataFrame as CSV

Parameters
  • options Object? (optional, default {})
    • options.delimiter string Delimiter to use (optional, default ',')

Returns (string | undefined) A CSV string if path is not set

toJSON

Exports the DataFrame as JSON

Parameters
  • options Object? (optional, default {})
    • options.prettify boolean Prettify JSON output (optional, default true)

Returns (string | undefined) A JSON string if path is not set

Kiwis

DataFrame

Returns a new DataFrame from the given data

Parameters

Returns DataFrame

Series

Returns a new Series from the given data

Parameters
  • data Array<any> An array of values

Returns Series

loadCSV

Loads a CSV string into a DataFrame

Parameters
  • csv string
  • options Object? Options (optional, default {})
    • options.delimiter string Delimiter of the file (optional, default ',')
    • options.prettify ("none" | "camelCase" | "snake_case") Prettify column names (optional, default 'none')

Returns DataFrame

isNA

Determines whether a value is N/A or not

Parameters
  • value any
  • options Object? Options (optional, default {})
    • options.keep Array<any> Array of falsy values not considered N/A (optional, default [0,false])

Returns boolean

PivotTable

Properties

  • length number The number of rows in the PivotTable
  • empty boolean Whether the PivotTable contains any row or not
  • columns Array<string> The columns of the PivotTable, starting with the pivots

rollup

Applies the given callback function on the leaves of the PivotTable, returning a DataFrame

Parameters
  • callback callback
  • options Object? (optional, default {})
    • options.name boolean Name to use for the column in the output DataFrame (optional, default 'data')

Returns DataFrame

count

Counts the number of leaves for each branch of the PivotTable

Returns DataFrame

sum

Computes the sum of a given column of the PivotTable

Parameters
  • column

Returns DataFrame

min

Computes the minimum value of a given column of the PivotTable

Parameters
  • column

Returns DataFrame

max

Computes the maximum value of a given column of the PivotTable

Parameters
  • column

Returns DataFrame

mean

Computes the mean of a given column of the PivotTable

Parameters
  • column

Returns number

median

Computes the mean of a given column of the PivotTable

Parameters
  • column

Returns number

std

Computes the standard deviation of a given column of the PivotTable

Parameters
  • column

Returns number

toString

Format the PivotTable for display

Returns string

show

Displays the DataFrame

toJSON

Exports the PivotTable as JSON

Parameters
  • options Object? (optional, default {})
    • options.prettify boolean Prettify JSON output (optional, default true)

Returns string

Series

Properties

  • length number The number of values in the Series
  • empty boolean Whether the Series contains any value or not

toArray

Returns the Series as an array

Returns Array<any>

clone

Clones the Series

Returns Series

get

Returns any row of the Series

Parameters

Returns any

first

Returns the first value of the Series

Returns any

last

Returns the last value of the Series

Returns any

head

Returns a new Series containing the first N values of the Series

Parameters
  • n number Number of values to select (optional, default 5)

Returns Series

tail

Returns a new Series containing the last N values of the Series

Parameters
  • n number Number of values to select (optional, default 5)

Returns Series

slice

Returns a new Series with a slice of the original values

Parameters
  • start number Zero-based index at which to start extraction
  • end number Zero-based index before which to end extraction (optional, default Series.length)

Returns Series

values

Returns the values of the Series as an iterable

Returns Iterable<any>

items

Returns an array of index/value pairs as an iterable

Returns Iterable<Array<number, any>>

forEach

Applies a callback function to each value of the Series

Parameters
  • callback callback

map

Returns a new Series populated with the results of a callback function applied on the Series

Parameters
  • callback callback

Returns Series

append

Appends new values to a Series

Parameters

Returns Series

insert

Inserts new values into a Series

Parameters
  • values (Object | Array<Object>) Value or array of values to insert into the Series
  • index number Index to insert the values at (optional, default 0)

Returns Series

concat

Concats another Series to the Series

Parameters
  • other Series
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

dropNA

Drops N/A values from the Series

Parameters
  • options Object? (optional, default {})
    • options.keep Array<any> Array of falsy values to keep in the Series (optional, default [0,false])
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

dropDuplicates

Drops duplicate values from the Series

Parameters
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

any

Returns true if any value of the series satisfies the given condition

Parameters
  • condition callback (optional, default !Kiwis.isNA)

Returns boolean

all

Returns true if all values of the series satisfy the given condition

Parameters
  • condition callback (optional, default !Kiwis.isNA)

Returns boolean

filter

Filters values of the Series

Parameters
  • filter callback Callback to apply
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

drop

Drops values from the Series

Parameters
  • filter callback Callback to apply
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

sort

Sorts the Series

Parameters
  • options Object? (optional, default {})
    • options.reverse boolean Sorts the Series in descending order (optional, default false)
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

shuffle

Shuffles the values of a Series

Parameters
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

unique

Returns the unique values in the Series as an array

Returns Array<any>

counts

Returns the number of occurences for each value in the Series

Parameters
  • options Object? (optional, default {})
    • options.sort boolean Sorts the counts (optional, default true)
    • options.reverse boolean Sorts the counts in descending order (optional, default true)

Returns Object Counts as an object of value/count pairs

frequencies

Returns the frequency for each value in the Series

Parameters
  • options Object? (optional, default {})
    • options.sort boolean Sorts the frequencies (optional, default true)
    • options.reverse boolean Sorts the frequencies in descending order (optional, default true)

Returns Object Counts as an object of value/frequencies pairs

round

Round the values in the Series

Parameters
  • digits number Number of digits for rounding (optional, default 0)
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

sum

Returns the sum of the values in the Series

Returns number

min

Returns the minimum value in the Series

Returns number

max

Returns the maximum value in the Series

Returns number

extent

Returns the extent of the Series

Returns [number, number]

mean

Returns the mean of the values in the Series

Returns number

median

Returns the median of the values in the Series

Returns number

std

Returns the standard deviation of the values in the Series

Returns number

toString

Format the Series for display

Returns string

show

Displays the Series

toCSV

Exports the Series as CSV

Parameters
  • options Object? (optional, default {})
    • options.name string Column name to use (optional, default 'series')

Returns (string | undefined) A JSON string if path is not set

toJSON

Exports the Series as a JSON file

Parameters
  • options Object? (optional, default {})
    • options.name string Column name to use (optional, default 'series')
    • options.prettify boolean Prettify JSON output (optional, default true)

Returns (string | undefined) A JSON string if path is not set

DataFrame

Parameters

Properties

  • length number The number of rows in the DataFrame
  • columns Array<string> The columns of the DataFrame
  • empty boolean Whether the DataFrame contains any row or not

toArray

Returns the DataFrame as an array

Returns Array<Object>

clone

Clones the DataFrame

Returns DataFrame

first

Returns the first row of the DataFrame

Returns Object

last

Returns the last row of the DataFrame

Returns Object

head

Returns a new DataFrame containing the first N rows of the DataFrame

Parameters

  • n number Number of rows to select (optional, default 5)

Returns DataFrame

tail

Returns a new DataFrame containing the last N rows of the DataFrame

Parameters

  • n number Number of rows to select (optional, default 5)

Returns DataFrame

slice

Returns a new DataFrame with a slice of the original rows

Parameters

  • start number Zero-based index at which to start extraction
  • end number Zero-based index before which to end extraction (optional, default DataFrame.length)

Returns DataFrame

rows

Returns the rows of the DataFrame as an iterable

Returns Iterable<Object>

items

Returns an array of index/row pairs as an iterable

Returns Iterable<Array<number, Object>>

forEach

Applies a callback function to each value of the Series

Parameters

  • callback callback

map

Returns a new Series populated with the results of a callback function applied on the DataFrame

Parameters

  • callback callback

Returns Series

append

Appends new rows to a DataFrame

Parameters

  • rows (Object | Array<Object>) Row or array of rows to append to the DataFrame
  • options Object? (optional, default {})
    • options.extend boolean Add new columns to the DataFrame if they do not exist (optional, default false)

Returns DataFrame

insert

Inserts new rows into a DataFrame

Parameters

  • rows (Object | Array<Object>) Row or array of rows to insert into the DataFrame
  • index number Index to insert the rows at (optional, default 0)
  • options Object? (optional, default {})
    • options.extend boolean Add new columns to the DataFrame if they do not exist (optional, default false)

Returns DataFrame

dropNA

Drops N/A values from the DataFrame

Parameters

  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether rows or columns should be dropped (optional, default 'rows')
    • options.keep Array<any> Array of falsy values to keep in the DataFrame (optional, default [0,false])
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

dropDuplicates

Drops duplicate rows from the DataFrame

Parameters

  • columns Array<string> Array of columns to consider for comparison (optional, default DataFrame.columns)
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

addColumn

Add a new column to the DataFrame

Parameters

  • name string Name of the new column
  • column (any | Array<any> | Series) Content of the new column as an array, a Series or any value (to be set on every rows)
  • options Object? (optional, default {})
    • options.fit ("auto" | "extend" | "trim") If the new column is not the same length as the DataFrame: drop the extra rows ('auto', length stays the same), extends the DataFrame ('extend', length is that of the new column), trim the DataFrame ('trim', length is that of the new column) (optional, default 'auto')
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

rename

Rename columns of the DataFrame

Parameters

  • map Object<key, string> Map of the columns to rename to their new names
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

reorder

Reorder the columns of the DataFrame

Parameters

  • names Array<string> Array containing the new order of the columns
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

filter

Filters columns or rows of the DataFrame

Parameters

  • filter (callback | Array<string>) Can be a callback (applied to rows or columns) or an array of column names to keep
  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether the callback should apply to rows or columns (optional, default 'rows')
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

drop

Drops columns or rows from the DataFrame

Parameters

  • filter (callback | Array<string>) Can be a callback (applied to rows or columns) or an array of column names to drop
  • options Object? (optional, default {})
    • options.axis ("rows" | "columns") Determines whether the callback should apply to rows or columns (optional, default 'rows')
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

sort

Sorts the DataFrame

Parameters

  • by (string | Array<string>) Key or array of keys to sort the DataFrame by
  • options Object? (optional, default {})
    • options.reverse boolean Sorts the DataFrame in descending order (optional, default false)
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)

Returns DataFrame

shuffle

Shuffles the rows or columns of a DataFrame

Parameters

  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current DataFrame instead of returning a new one (optional, default false)
    • options.axis ("rows" | "columns") Determines whether rows or columns should be shuffled (optional, default 'rows')

Returns DataFrame

show

Displays the DataFrame

Returns DataFrame

saveCSV

Saves the DataFrame as a CSV file

Parameters

  • path string Path of the file to save
  • options Object? (optional, default {})
    • options.delimiter string Delimiter to use (optional, default ',')

saveJSON

Saves the DataFrame as a JSON file

Parameters

  • path string Path of the file to save
  • options Object? (optional, default {})
    • options.prettify boolean Prettify JSON output (optional, default true)

Kiwis

DataFrame

Returns a new DataFrame from the given data

Parameters

Returns DataFrame

Series

Returns a new Series from the given data

Parameters

  • data Array<any> An array of values

Returns Series

loadCSV

Loads a CSV file into a DataFrame

Parameters

  • path string Path of the file to load
  • options Object? Options (optional, default {})
    • options.delimiter string Delimiter of the file (optional, default ',')
    • options.encoding string Encoding of the file (optional, default 'utf8')
    • options.prettify ("none" | "camelCase" | "snake_case") Prettify column names (optional, default 'none')

Returns DataFrame

isNA

Determines whether a value is N/A or not

Parameters

  • value any
  • options Object? Options (optional, default {})
    • options.keep Array<any> Array of falsy values not considered N/A (optional, default [0,false])

Returns boolean

Series

Parameters

  • data (Array<any> | Series) An array of values or a Series

Properties

  • length number The number of values in the Series
  • empty boolean Whether the Series contains any value or not

toArray

Returns the Series as an array

Returns Array<any>

clone

Clones the Series

Returns Series

first

Returns the first value of the Series

Returns any

last

Returns the last value of the Series

Returns any

head

Returns a new Series containing the first N values of the Series

Parameters

  • n number Number of values to select (optional, default 5)

Returns Series

tail

Returns a new Series containing the last N values of the Series

Parameters

  • n number Number of rows to select (optional, default 5)

Returns Series

slice

Returns a new Series with a slice of the original values

Parameters

  • start number Zero-based index at which to start extraction
  • end number Zero-based index before which to end extraction (optional, default Series.length)

Returns Series

values

Returns the values of the Series as an iterable

Returns Iterable<any>

items

Returns an array of index/value pairs as an iterable

Returns Iterable<Array<number, any>>

forEach

Applies a callback function to each value of the Series

Parameters

  • callback callback

map

Returns a new Series populated with the results of a callback function applied on the Series

Parameters

  • callback callback

Returns Series

append

Appends new values to a Series

Parameters

Returns Series

insert

Inserts new values into a Series

Parameters

  • values (Object | Array<Object>) Value or array of values to insert into the Series
  • index number Index to insert the values at (optional, default 0)

Returns Series

dropNA

Drops N/A values from the Series

Parameters

  • options Object? (optional, default {})
    • options.keep Array<any> Array of falsy values to keep in the Series (optional, default [0,false])
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

dropDuplicates

Drops duplicate values from the Series

Parameters

  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

filter

Filters values of the Series

Parameters

  • filter callback Callback to apply
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

drop

Drops values from the Series

Parameters

  • filter callback Callback to apply
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

sort

Sorts the Series

Parameters

  • options Object? (optional, default {})
    • options.reverse boolean Sorts the Series in descending order (optional, default false)
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

shuffle

Shuffles the values of a Series

Parameters

  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

round

Round the values in the Series

Parameters

  • digits number Number of digits for rounding (optional, default 0)
  • options Object? (optional, default {})
    • options.inPlace boolean Changes the current Series instead of returning a new one (optional, default false)

Returns Series

sum

Returns the sum of the values in the Series

Returns number

min

Returns the minimum value in the Series

Returns number

max

Returns the maximum value in the Series

Returns number

mean

Returns the mean of the values in the Series

Returns number

median

Returns the median of the values in the Series

Returns number

std

Returns the standard deviation of the values in the Series

Returns number

show

Displays the Series

Returns Series

saveCSV

Saves the Series as a CSV file

Parameters

  • path string Path of the file to save
  • options Object? (optional, default {})
    • options.name string Column name to use (optional, default 'series')

saveJSON

Saves the Series as a JSON file

Parameters

  • path string Path of the file to save
  • options Object? (optional, default {})
    • options.name string Column name to use (optional, default 'series')
    • options.prettify boolean Prettify JSON output (optional, default true)

Readme

Keywords

Package Sidebar

Install

npm i kiwis-no-fs

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

101 kB

Total Files

7

Last publish

Collaborators

  • tomfevrier