UNPKG

kiwis

Version:

A Pandas-inspired data wrangling toolkit in JavaScript

1,512 lines (1,044 loc) 57 kB
# Kiwis 🥝 ## A Pandas-inspired data wrangling toolkit in JavaScript</h2> ### Installation `npm install kiwis` <!-- ![](assets/logo-kiwis-small.png) --> ### Getting started ```js 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 <!-- Generated by documentation.js. Update this documentation by updating the source code. --> #### Table of Contents - [Kiwis](#kiwis) - [DataFrame](#dataframe) - [Parameters](#parameters) - [Examples](#examples) - [Series](#series) - [Parameters](#parameters-1) - [Examples](#examples-1) - [loadCSV](#loadcsv) - [Parameters](#parameters-2) - [Examples](#examples-2) - [parseCSV](#parsecsv) - [Parameters](#parameters-3) - [Examples](#examples-3) - [isNA](#isna) - [Parameters](#parameters-4) - [Examples](#examples-4) - [DataFrame](#dataframe-1) - [Properties](#properties) - [toArray](#toarray) - [clone](#clone) - [get](#get) - [Parameters](#parameters-5) - [Examples](#examples-5) - [first](#first) - [last](#last) - [find](#find) - [Parameters](#parameters-6) - [Examples](#examples-6) - [set](#set) - [Parameters](#parameters-7) - [Examples](#examples-7) - [head](#head) - [Parameters](#parameters-8) - [Examples](#examples-8) - [tail](#tail) - [Parameters](#parameters-9) - [Examples](#examples-9) - [slice](#slice) - [Parameters](#parameters-10) - [Examples](#examples-10) - [rows](#rows) - [Examples](#examples-11) - [items](#items) - [Examples](#examples-12) - [forEach](#foreach) - [Parameters](#parameters-11) - [Examples](#examples-13) - [map](#map) - [Parameters](#parameters-12) - [Examples](#examples-14) - [replace](#replace) - [Parameters](#parameters-13) - [Examples](#examples-15) - [append](#append) - [Parameters](#parameters-14) - [Examples](#examples-16) - [insert](#insert) - [Parameters](#parameters-15) - [Examples](#examples-17) - [concat](#concat) - [Parameters](#parameters-16) - [Examples](#examples-18) - [join](#join) - [Parameters](#parameters-17) - [Examples](#examples-19) - [addColumn](#addcolumn) - [Parameters](#parameters-18) - [Examples](#examples-20) - [rename](#rename) - [Parameters](#parameters-19) - [Examples](#examples-21) - [reorder](#reorder) - [Parameters](#parameters-20) - [Examples](#examples-22) - [dropNA](#dropna) - [Parameters](#parameters-21) - [Examples](#examples-23) - [dropDuplicates](#dropduplicates) - [Parameters](#parameters-22) - [Examples](#examples-24) - [filter](#filter) - [Parameters](#parameters-23) - [Examples](#examples-25) - [drop](#drop) - [Parameters](#parameters-24) - [Examples](#examples-26) - [sort](#sort) - [Parameters](#parameters-25) - [Examples](#examples-27) - [shuffle](#shuffle) - [Parameters](#parameters-26) - [Examples](#examples-28) - [pivot](#pivot) - [Parameters](#parameters-27) - [Examples](#examples-29) - [toString](#tostring) - [show](#show) - [toCSV](#tocsv) - [Parameters](#parameters-28) - [Examples](#examples-30) - [toJSON](#tojson) - [Parameters](#parameters-29) - [Examples](#examples-31) - [Series](#series-1) - [Properties](#properties-1) - [toArray](#toarray-1) - [clone](#clone-1) - [get](#get-1) - [Parameters](#parameters-30) - [Examples](#examples-32) - [first](#first-1) - [last](#last-1) - [find](#find-1) - [Parameters](#parameters-31) - [Examples](#examples-33) - [set](#set-1) - [Parameters](#parameters-32) - [Examples](#examples-34) - [head](#head-1) - [Parameters](#parameters-33) - [Examples](#examples-35) - [tail](#tail-1) - [Parameters](#parameters-34) - [Examples](#examples-36) - [slice](#slice-1) - [Parameters](#parameters-35) - [Examples](#examples-37) - [values](#values) - [Examples](#examples-38) - [items](#items-1) - [Examples](#examples-39) - [forEach](#foreach-1) - [Parameters](#parameters-36) - [Examples](#examples-40) - [map](#map-1) - [Parameters](#parameters-37) - [Examples](#examples-41) - [append](#append-1) - [Parameters](#parameters-38) - [Examples](#examples-42) - [insert](#insert-1) - [Parameters](#parameters-39) - [Examples](#examples-43) - [concat](#concat-1) - [Parameters](#parameters-40) - [Examples](#examples-44) - [dropNA](#dropna-1) - [Parameters](#parameters-41) - [Examples](#examples-45) - [dropDuplicates](#dropduplicates-1) - [Parameters](#parameters-42) - [Examples](#examples-46) - [any](#any) - [Parameters](#parameters-43) - [Examples](#examples-47) - [all](#all) - [Parameters](#parameters-44) - [Examples](#examples-48) - [filter](#filter-1) - [Parameters](#parameters-45) - [Examples](#examples-49) - [drop](#drop-1) - [Parameters](#parameters-46) - [Examples](#examples-50) - [sort](#sort-1) - [Parameters](#parameters-47) - [Examples](#examples-51) - [shuffle](#shuffle-1) - [Parameters](#parameters-48) - [Examples](#examples-52) - [unique](#unique) - [counts](#counts) - [Parameters](#parameters-49) - [Examples](#examples-53) - [frequencies](#frequencies) - [Parameters](#parameters-50) - [Examples](#examples-54) - [round](#round) - [Parameters](#parameters-51) - [Examples](#examples-55) - [reduce](#reduce) - [Parameters](#parameters-52) - [Examples](#examples-56) - [sum](#sum) - [min](#min) - [max](#max) - [extent](#extent) - [mean](#mean) - [median](#median) - [std](#std) - [toString](#tostring-1) - [show](#show-1) - [toCSV](#tocsv-1) - [Parameters](#parameters-53) - [Examples](#examples-57) - [toJSON](#tojson-1) - [Parameters](#parameters-54) - [Examples](#examples-58) - [PivotTable](#pivottable) - [Properties](#properties-2) - [rollup](#rollup) - [Parameters](#parameters-55) - [Examples](#examples-59) - [count](#count) - [Examples](#examples-60) - [sum](#sum-1) - [Parameters](#parameters-56) - [Examples](#examples-61) - [min](#min-1) - [Parameters](#parameters-57) - [Examples](#examples-62) - [max](#max-1) - [Parameters](#parameters-58) - [Examples](#examples-63) - [mean](#mean-1) - [Parameters](#parameters-59) - [Examples](#examples-64) - [median](#median-1) - [Parameters](#parameters-60) - [Examples](#examples-65) - [std](#std-1) - [Parameters](#parameters-61) - [Examples](#examples-66) - [toString](#tostring-2) - [show](#show-2) - [toJSON](#tojson-2) - [Parameters](#parameters-62) - [Examples](#examples-67) ### Kiwis #### DataFrame Returns a new DataFrame from the given data ##### Parameters - `data` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** An array of objects ##### Examples ```javascript const kw = require('kiwis'); const df = kw.DataFrame([ { name: 'Marvin', surname: '', occupation: 'Paranoid Android' }, { name: 'Zaphod', surname: 'Beeblebrox', occupation: 'President of the Galaxy' }, { name: 'Arthur', surname: 'Dent', occupation: null } ]); console.log(df.length) // 3 console.log(df.columns) // ['name', 'surname', 'occupation'] console.log(df.empty) // false ``` Returns **[DataFrame](#dataframe)** #### Series Returns a new Series from the given data ##### Parameters - `data` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** An array of values ##### Examples ```javascript const kw = require('kiwis'); const series = kw.Series([1, 1, 2, 3, 5, 8, 13, 21, 34]); console.log(series.length) // 9 console.log(series.empty) // false ``` Returns **[Series](#series)** #### loadCSV Loads a CSV file into a DataFrame ##### Parameters - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path of the file to load - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Options (optional, default `{}`) - `options.delimiter` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Delimiter of the file (optional, default `','`) - `options.encoding` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Encoding of the file (optional, default `'utf8'`) - `options.prettify` **(`"none"` \| `"camelCase"` \| `"snake_case"`)** Prettify column names (optional, default `'none'`) ##### Examples ```javascript const kw = require('kiwis'); // Loads a CSV file const df = kw.loadCSV('myAwesomeData.csv'); // Loads a TSV file and prettify the columns in camelCase const df = kw.loadCSV('myAwesomeData.tsv', { delimiter: '\t', prettify; 'camelCase' }); ``` Returns **[DataFrame](#dataframe)** #### parseCSV Parses a CSV string into a DataFrame ##### Parameters - `csv` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** CSV string to parse - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Options (optional, default `{}`) - `options.delimiter` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Delimiter of the file (optional, default `','`) - `options.prettify` **(`"none"` \| `"camelCase"` \| `"snake_case"`)** Prettify column names (optional, default `'none'`) ##### Examples ```javascript const kw = require('kiwis'); // Parses a CSV string const df = kw.parseCSV(` name,surname,occupation\n Marvin,,Paranoid Android\n Zaphod,Beeblebrox,President of the Galaxy\n Arthur,Dent,\n `); ``` Returns **[DataFrame](#dataframe)** #### isNA Determines whether a value is N/A or not ##### Parameters - `value` **any** - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** Options (optional, default `{}`) - `options.keep` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** Array of falsy values not considered N/A (optional, default `[0,false]`) ##### Examples ```javascript Kiwis.isNA('kiwi'); // false Kiwis.isNA(''); // true Kiwis.isNA('', { keep: [0, false, ''] }); // false ``` Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** ### DataFrame #### Properties - `length` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The number of rows in the DataFrame - `empty` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether the DataFrame contains any row or not - `columns` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** The columns of the DataFrame #### toArray Returns the DataFrame as an array Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** #### clone Clones the DataFrame Returns **[DataFrame](#dataframe)** #### get Returns any row of the DataFrame ##### Parameters - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ##### Examples ```javascript // Returns the row at index 4 df.get(4); ``` Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** #### first Returns the first row of the DataFrame Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** #### last Returns the last row of the DataFrame Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** #### find Returns a specific row in the DataFrame ##### Parameters - `condition` **callback** The returned row is the first one that matches this condition ##### Examples ```javascript // Returns the row where the 'name' is 'Marvin' df.find(row => row.name === 'Marvin'); ``` Returns **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** #### set Sets the content of a cell in the DataFrame ##### Parameters - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** - `column` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** - `value` **any** ##### Examples ```javascript // Sets the value for 'name' on the 42nd row to 'Slartibartfast' df.set(42, 'name', 'Slartibartfast'); ``` #### head Returns a new DataFrame containing the first N rows of the DataFrame ##### Parameters - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of rows to select (optional, default `5`) ##### Examples ```javascript // Returns a new DataFrame with the first 10 rows df.head(10); ``` Returns **[DataFrame](#dataframe)** #### tail Returns a new DataFrame containing the last N rows of the DataFrame ##### Parameters - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of rows to select (optional, default `5`) ##### Examples ```javascript // Returns a new DataFrame with the last 5 rows df.tail(); ``` Returns **[DataFrame](#dataframe)** #### slice Returns a new DataFrame with a slice of the original rows ##### Parameters - `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zero-based index at which to start extraction - `end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zero-based index before which to end extraction (optional, default `DataFrame.length`) ##### Examples ```javascript // Returns a new DataFrame with rows starting at index 10 df.slice(10); // Returns a new DataFrame with rows between index 24 (included) and 42 (excluded) df.slice(24, 42); ``` Returns **[DataFrame](#dataframe)** #### rows Returns the rows of the DataFrame as an iterable ##### Examples ```javascript for (let row of df.rows()) { console.log(row); } ``` Returns **Iterable&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>** #### items Returns an array of index/row pairs as an iterable ##### Examples ```javascript for (let [index, row] of df.items()) { console.log(index, row); } ``` Returns **Iterable&lt;[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>>** #### forEach Applies a callback function to each row of the DataFrame ##### Parameters - `callback` **callback** ##### Examples ```javascript // Displays each element in the 'name' column of the DataFrame df.forEach(row => console.log(row.name)); ``` #### map Returns a new Series populated with the results of a callback function applied on each row the DataFrame ##### Parameters - `callback` **callback** ##### Examples ```javascript // Returns a Series of full names by joining the name and surname for each row of the DataFrame df.map(row => [row.name, row.surname].join(' ')); ``` Returns **[Series](#series)** #### replace Replaces all occurences of the given value in the DataFrame by another value ##### Parameters - `oldValue` **any** - `newValue` **any** - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) - `options.columns` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Columns to replace into (optional, default `DataFrame.columns`) ##### Examples ```javascript // Replaces all occurrences of 'panda' with 'kiwi' in the column 'animal' df.replace('panda', 'kiwi', { inPlace: true, columns: 'animal' }); ``` Returns **[DataFrame](#dataframe)** #### append Appends new rows to a DataFrame ##### Parameters - `rows` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>)** Row or array of rows to append to the DataFrame - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.extend` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Adds new columns to the DataFrame if they do not already exist (optional, default `false`) ##### Examples ```javascript const rows = [ { name: 'Marvin', occupation: 'Robot' }, { name: 'Zaphod Beeblebrox', occupation: 'President of the Galaxy' } ]; df.append(rows, { extend: true }); ``` Returns **[DataFrame](#dataframe)** #### insert Inserts new rows into a DataFrame ##### Parameters - `rows` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>)** Row or array of rows to insert into the DataFrame - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index to insert the rows at (optional, default `0`) - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.extend` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Adds new columns to the DataFrame if they do not already exist (optional, default `false`) ##### Examples ```javascript // Inserts a new row at index 2 in the DataFrame df.insert({ name: 'Trillian', species: 'human' }, 2, { extend: true }); ``` Returns **[DataFrame](#dataframe)** #### concat Concatenates another DataFrame to the DataFrame ##### Parameters - `other` **[DataFrame](#dataframe)** - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.extend` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Adds new columns to the DataFrame if they do not already exist (optional, default `false`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Concatenates df1 and df2, adding columns from df2 into df1 if they do not exist df1.concat(df2, { inPlace: true, extend: true }); ``` Returns **[DataFrame](#dataframe)** #### join Performs a join of two DataFrames on a given column ##### Parameters - `other` **[DataFrame](#dataframe)** - `column` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Column to join the DataFrames on - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.how` **(`"inner"` \| `"outer"` \| `"left"` \| `"right"`)** How the DataFrames should be joined: `'inner'` only keeps the intersection of the rows, `'outer'` keeps the union of the rows, `'left'` only keeps rows from the current DataFrame, and `'right'` only keeps rows from the `other` DataFrame (optional, default `'inner'`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Joins DataFrames df1 and df2 along their column 'id', keeping only the rows from df1 df1.join(df2, 'id', { inPlace: true, how: 'left' }); ``` Returns **[DataFrame](#dataframe)** #### addColumn Adds a new column to the DataFrame ##### Parameters - `name` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the new column - `column` **(any | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any> | [Series](#series))** Content of the new column as an array, a Series or any value (to be set on every rows) - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.extend` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** If the new column is not the same length as the DataFrame, extends the DataFrame (optional, default `false`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Adds a new column 'fullName' by applying a function on the DataFrame df.addColumn( 'fullName', df.map(row => [row.name, row.surname].join(' ')), { inPlace: true } ); // Adds a new column 'species', with 'human' on every rows df.addColumn('species', 'human', { inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### rename Rename columns of the DataFrame ##### Parameters - `map` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)&lt;key, [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** Map of the columns to rename to their new names - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Renames column 'occupation' into 'job' df.rename({ occupation: 'job' }, { inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### reorder Reorder the columns of the DataFrame ##### Parameters - `names` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>** Array containing the new order of the columns - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript console.log(df.columns) // ['occupation', 'species', 'name'] df.reorder(['name', 'occupation', 'species'], { inPlace: true }); console.log(df.columns) // ['name', 'occupation', 'species'] ``` Returns **[DataFrame](#dataframe)** #### dropNA Drops N/A values from the DataFrame ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.axis` **(`"rows"` \| `"columns"`)** Determines whether rows or columns should be dropped (optional, default `'rows'`) - `options.keep` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** Array of falsy values to keep in the DataFrame (optional, default `[0,false]`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Drops all rows containg N/A values df.dropNA({ inPlace: true }); // Drops all columns containing N/A values (but keeps empty strings as well as 0 and false) df.dropNA({ axis: 'columns', keep: [0, false, ''], inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### dropDuplicates Drops duplicate rows from the DataFrame ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.columns` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Column or array of columns to consider for comparison (optional, default `DataFrame.columns`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Drops duplicate rows with similar values for 'name' df.dropDuplicates({ columns: 'name', inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### filter Filters columns or rows of the DataFrame ##### Parameters - `filter` **(callback | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Can be a callback (applied to rows or columns) or an array of column names to keep - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.axis` **(`"rows"` \| `"columns"`)** Determines whether the callback should apply to rows or columns (optional, default `'rows'`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Only keeps the 'date' and 'url' columns df.filter(['date', 'url'], { inPlace: true }); // Only keeps rows whose date is 4/20/20 df.filter(row => row.date === '2020-04-20', { inPlace: true }); // Only keeps columns whose name contains 'data' df.filter(column => column.includes('data'), { axis: 'columns', inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### drop Drops columns or rows from the DataFrame ##### Parameters - `filter` **(callback | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Can be a callback (applied to rows or columns) or an array of column names to drop - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.axis` **(`"rows"` \| `"columns"`)** Determines whether the callback should apply to rows or columns (optional, default `'rows'`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Removes the 'date' and 'url' columns df.drop(['date', 'url'], { inPlace: true }); // Removes all rows whose date is 4/20/20 df.drop(row => row.date === '2020-04-20', { inPlace: true }); // Removes columns whose name contains 'data' df.drop(column => column.includes('data'), { axis: 'columns', inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### sort Sorts the DataFrame ##### Parameters - `by` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Key or array of keys to sort the DataFrame by - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the DataFrame in descending order (optional, default `false`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Sorts the DataFrame alphabetically by 'name' df.sort('name', { inPlace: true }); // Sorts the DataFrame in descending ordr by 'age' df.sort('age', { reverse: true, inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### shuffle Shuffles the rows or columns of a DataFrame ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.axis` **(`"rows"` \| `"columns"`)** Determines whether rows or columns should be shuffled (optional, default `'rows'`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current DataFrame instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Shuffles the columns of the DataFrame df.shuffle({ axis: 'columns', inPlace: true }); ``` Returns **[DataFrame](#dataframe)** #### pivot Returns a PivotTable along the given columns ##### Parameters - `columns` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>)** Column or array of columns to pivot along ##### Examples ```javascript // Returns a PivotTable along columns 'sector' and 'date' df.pivot(['sector', 'date']); ``` Returns **[PivotTable](#pivottable)** #### toString Formats the DataFrame for display Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** #### show Displays the DataFrame #### toCSV Exports the DataFrame as CSV ##### Parameters - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path of the file to save (optional, default `null`) - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.delimiter` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Delimiter to use (optional, default `','`) ##### Examples ```javascript df.toCSV('myAwesomeData.csv'); // to CSV df.toCSV('myAwesomeData.tsv', { delimiter: '\t' }); // to TSV ``` Returns **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** A CSV string if `path` is not set #### toJSON Exports the DataFrame as JSON ##### Parameters - `path` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Path of the file to save (optional, default `null`) - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.prettify` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Prettify JSON output (optional, default `true`) ##### Examples ```javascript df.toJSON('myAwesomeData.json'); ``` Returns **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) \| [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** A JSON string if `path` is not set ### Series #### Properties - `length` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The number of values in the Series - `empty` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether the Series contains any value or not #### toArray Returns the Series as an array Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** #### clone Clones the Series Returns **[Series](#series)** #### get Returns any row of the Series ##### Parameters - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** ##### Examples ```javascript // Returns the value at index 4 series.get(4); ``` Returns **any** #### first Returns the first value of the Series Returns **any** #### last Returns the last value of the Series Returns **any** #### find Returns a specific value in the Series ##### Parameters - `condition` **callback** The returned value is the first one that matches this condition ##### Examples ```javascript // Returns the value that contains 'fast' series.find(value => value.includes('fast')); ``` Returns **any** #### set Sets a value in the Series ##### Parameters - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** - `value` **any** ##### Examples ```javascript // Sets the 42nd value of the Series to 'Slartibartfast' df.set(42, 'Slartibartfast'); ``` #### head Returns a new Series containing the first N values of the Series ##### Parameters - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of values to select (optional, default `5`) ##### Examples ```javascript // Returns a new Series with the first 10 values series.head(10); ``` Returns **[Series](#series)** #### tail Returns a new Series containing the last N values of the Series ##### Parameters - `n` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of values to select (optional, default `5`) ##### Examples ```javascript // Returns a new Series with the last 5 values series.tail(); ``` Returns **[Series](#series)** #### slice Returns a new Series with a slice of the original values ##### Parameters - `start` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zero-based index at which to start extraction - `end` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Zero-based index before which to end extraction (optional, default `Series.length`) ##### Examples ```javascript // Returns a new Series with values starting at index 10 series.slice(10); // Returns a new Series with values between index 24 (included) and 42 (excluded) series.slice(24, 42); ``` Returns **[Series](#series)** #### values Returns the values of the Series as an iterable ##### Examples ```javascript for (let value of series.values()) { console.log(value); } ``` Returns **Iterable&lt;any>** #### items Returns an array of index/value pairs as an iterable ##### Examples ```javascript for (let [index, value] of series.items()) { console.log(index, value); } ``` Returns **Iterable&lt;[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number), any>>** #### forEach Applies a callback function to each value of the Series ##### Parameters - `callback` **callback** ##### Examples ```javascript // Displays each value of the Series series.forEach(value => console.log(value)); ``` #### map Returns a new Series populated with the results of a callback function applied on the Series ##### Parameters - `callback` **callback** ##### Examples ```javascript // Double each value in the Series series.map(value => value * 2); ``` Returns **[Series](#series)** #### append Appends new values to a Series ##### Parameters - `values` **([Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object) \| [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>)** Value or array of values to append to the Series ##### Examples ```javascript series.append([42, 101]); ``` Returns **[Series](#series)** #### insert Inserts new values into a Series ##### Parameters - `values` **(any | [Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>)** Value or array of values to insert into the Series - `index` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Index to insert the values at (optional, default `0`) ##### Examples ```javascript // Inserts value 42 at index 2 in the Series series.insert(42, 2); ``` Returns **[Series](#series)** #### concat Concats another Series to the Series ##### Parameters - `other` **[Series](#series)** - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Concatenates series1 and series2 series1.concat(series2, { inPlace: true }); ``` Returns **[Series](#series)** #### dropNA Drops N/A values from the Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.keep` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** Array of falsy values to keep in the Series (optional, default `[0,false]`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Drop all N/A values from the Series series.dropNA({ inPlace: true }); // Drop all N/A values but keep empty strings series.dropNA({ keep: [''], inPlace: true }); ``` Returns **[Series](#series)** #### dropDuplicates Drops duplicate values from the Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript series.dropDuplicates({ inPlace: true }); ``` Returns **[Series](#series)** #### any Returns true if any value of the series satisfies the given condition ##### Parameters - `condition` **callback** (optional, default `!Kiwis.isNA`) ##### Examples ```javascript // Returns true if any value is not N/A series.any(); // Returns true if any value is greater than 42 series.any(value => value > 42); ``` Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** #### all Returns true if all values of the series satisfy the given condition ##### Parameters - `condition` **callback** (optional, default `!Kiwis.isNA`) ##### Examples ```javascript // Returns true if all values are not N/A series.all(); // Returns true if all values are greater than 42 series.all(value => value > 42); ``` Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** #### filter Filters values of the Series ##### Parameters - `filter` **callback** Callback to apply - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Only keeps values greater than 42 series.filter(value => value > 42, { inPlace: true }); ``` Returns **[Series](#series)** #### drop Drops values from the Series ##### Parameters - `filter` **callback** Callback to apply - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Only drops values greater than 42 series.drop(value => value > 42, { inPlace: true }); ``` Returns **[Series](#series)** #### sort Sorts the Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the Series in descending order (optional, default `false`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Sorts the Series in descending order series.sort({ reverse: true, inPlace: true }); ``` Returns **[Series](#series)** #### shuffle Shuffles the values of a Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript series.shuffle({ inPlace: true }); ``` Returns **[Series](#series)** #### unique Returns the unique values in the Series as an array Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;any>** #### counts Returns the number of occurrences for each value in the Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.sort` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the counts (optional, default `true`) - `options.reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the counts in descending order (optional, default `true`) ##### Examples ```javascript // Returns the number of occurrences for each value in the Series, in ascending order series.counts({ reverse: false }); ``` Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[any, [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)]>** Counts as an array of of value/count pairs #### frequencies Returns the frequency for each value in the Series ##### Parameters - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.sort` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the frequencies (optional, default `true`) - `options.reverse` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Sorts the frequencies in descending order (optional, default `true`) ##### Examples ```javascript // Returns the frequency for each value in the Series, in ascending order series.frequencies({ reverse: false }); ``` Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;\[any, [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)]>** Counts as an array of value/frequency pairs #### round Round the values in the Series ##### Parameters - `digits` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of digits for rounding (optional, default `0`) - `options` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)?** (optional, default `{}`) - `options.inPlace` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Changes the current Series instead of returning a new one (optional, default `false`) ##### Examples ```javascript // Rounds all values in the digits to 2 decimal points series.round(2, { inPlace: true }); // Truncates all values in the Series series.round(0, { inPlace: true }); ``` Returns **[Series](#series)** #### reduce Returns a single reduced value after applying the given callback to the values of the Series ##### Parameters - `callback` **callback** - `initial` **any** Value to use as the first argument to the first call of the callback (optional, default `Series.first()`) ##### Examples ```javascript // Returns the sum of all values in the Series series.reduce((acc, value) => acc + value); // Equivalent to series.sum() // Returns the product of all values in the Series series.reduce((acc, value) => acc * value, 1); ``` Returns **any** #### sum Returns the sum of the values in the Series Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** #### min Returns the minimum value in the Series Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** #### max Returns the maximum value in the Series Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** #### extent Returns the e