Kiwis 🥝
A Pandas-inspired data wrangling toolkit in JavaScript
Installation
npm install kiwis
Getting started
const kw = ; const h2g2Characters = kw; h2g2Characters; /*| name | surname | occupation=================================================0 | Marvin | N/A | Paranoid Android1 | Zaphod | Beeblebrox | President of the Galaxy2 | Arthur | Dent | N/A [3 rows × 3 columns]Columns: name, surname, occupation*/ console; /*{ name: 'Zaphod', surname: 'Beeblebrox', occupation: 'President of the Galaxy'}*/ h2g2Charactersname; /*0 | Marvin1 | Zaphod2 | Arthur Length: 3*/
Documentation
Table of Contents
- DataFrame
- Kiwis
- PivotTable
- Series
DataFrame
Properties
length
number The number of rows in the DataFrameempty
boolean Whether the DataFrame contains any row or notcolumns
Array<string> The columns of the DataFrame
toArray
Returns the DataFrame as an array
clone
Clones the DataFrame
Returns DataFrame
get
Returns any row of the DataFrame
Parameters
index
number
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, default5
)
Returns DataFrame
tail
Returns a new DataFrame containing the last N rows of the DataFrame
Parameters
n
number Number of rows to select (optional, default5
)
Returns DataFrame
slice
Returns a new DataFrame with a slice of the original rows
Parameters
start
number Zero-based index at which to start extractionend
number Zero-based index before which to end extraction (optional, defaultDataFrame.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
anynewValue
anyoptions
Object? (optional, default{}
)
append
Appends new rows to a DataFrame
Parameters
rows
(Object | Array<Object>) Row or array of rows to append to the DataFrameoptions
Object? (optional, default{}
)options.extend
boolean Add new columns to the DataFrame if they do not already exist (optional, defaultfalse
)
Returns DataFrame
insert
Inserts new rows into a DataFrame
Parameters
rows
(Object | Array<Object>) Row or array of rows to insert into the DataFrameindex
number Index to insert the rows at (optional, default0
)options
Object? (optional, default{}
)options.extend
boolean Add new columns to the DataFrame if they do not already exist (optional, defaultfalse
)
Returns DataFrame
concat
Concats another DataFrame to the DataFrame
Parameters
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, defaultfalse
)
Returns DataFrame
dropDuplicates
Drops duplicate rows from the DataFrame
Parameters
options
Object? (optional, default{}
)
Returns DataFrame
addColumn
Add a new column to the DataFrame
Parameters
name
string Name of the new columncolumn
(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{}
)
Returns DataFrame
rename
Rename columns of the DataFrame
Parameters
map
Object<key, string> Map of the columns to rename to their new namesoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current DataFrame instead of returning a new one (optional, defaultfalse
)
Returns DataFrame
reorder
Reorder the columns of the DataFrame
Parameters
names
Array<string> Array containing the new order of the columnsoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current DataFrame instead of returning a new one (optional, defaultfalse
)
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 keepoptions
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, defaultfalse
)
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 dropoptions
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, defaultfalse
)
Returns DataFrame
sort
Sorts the DataFrame
Parameters
by
(string | Array<string>) Key or array of keys to sort the DataFrame byoptions
Object? (optional, default{}
)
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, defaultfalse
)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, defaulttrue
)
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
stringoptions
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
anyoptions
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 PivotTableempty
boolean Whether the PivotTable contains any row or notcolumns
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
callbackoptions
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, defaulttrue
)
Returns string
Series
Properties
length
number The number of values in the Seriesempty
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
index
number
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, default5
)
Returns Series
tail
Returns a new Series containing the last N values of the Series
Parameters
n
number Number of values to select (optional, default5
)
Returns Series
slice
Returns a new Series with a slice of the original values
Parameters
start
number Zero-based index at which to start extractionend
number Zero-based index before which to end extraction (optional, defaultSeries.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 Seriesindex
number Index to insert the values at (optional, default0
)
Returns Series
concat
Concats another Series to the Series
Parameters
other
Seriesoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
Returns Series
dropNA
Drops N/A values from the Series
Parameters
options
Object? (optional, default{}
)
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, defaultfalse
)
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 applyoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
Returns Series
drop
Drops values from the Series
Parameters
filter
callback Callback to applyoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
Returns Series
sort
Sorts the Series
Parameters
options
Object? (optional, default{}
)
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, defaultfalse
)
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{}
)
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{}
)
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, default0
)options
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
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
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{}
)
Returns (string | undefined) A JSON string if path
is not set
DataFrame
Parameters
Properties
length
number The number of rows in the DataFramecolumns
Array<string> The columns of the DataFrameempty
boolean Whether the DataFrame contains any row or not
toArray
Returns the DataFrame as an array
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, default5
)
Returns DataFrame
tail
Returns a new DataFrame containing the last N rows of the DataFrame
Parameters
n
number Number of rows to select (optional, default5
)
Returns DataFrame
slice
Returns a new DataFrame with a slice of the original rows
Parameters
start
number Zero-based index at which to start extractionend
number Zero-based index before which to end extraction (optional, defaultDataFrame.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 DataFrameoptions
Object? (optional, default{}
)options.extend
boolean Add new columns to the DataFrame if they do not exist (optional, defaultfalse
)
Returns DataFrame
insert
Inserts new rows into a DataFrame
Parameters
rows
(Object | Array<Object>) Row or array of rows to insert into the DataFrameindex
number Index to insert the rows at (optional, default0
)options
Object? (optional, default{}
)options.extend
boolean Add new columns to the DataFrame if they do not exist (optional, defaultfalse
)
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, defaultfalse
)
Returns DataFrame
dropDuplicates
Drops duplicate rows from the DataFrame
Parameters
columns
Array<string> Array of columns to consider for comparison (optional, defaultDataFrame.columns
)options
Object? (optional, default{}
)options.inPlace
boolean Changes the current DataFrame instead of returning a new one (optional, defaultfalse
)
Returns DataFrame
addColumn
Add a new column to the DataFrame
Parameters
name
string Name of the new columncolumn
(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, defaultfalse
)
Returns DataFrame
rename
Rename columns of the DataFrame
Parameters
map
Object<key, string> Map of the columns to rename to their new namesoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current DataFrame instead of returning a new one (optional, defaultfalse
)
Returns DataFrame
reorder
Reorder the columns of the DataFrame
Parameters
names
Array<string> Array containing the new order of the columnsoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current DataFrame instead of returning a new one (optional, defaultfalse
)
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 keepoptions
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, defaultfalse
)
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 dropoptions
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, defaultfalse
)
Returns DataFrame
sort
Sorts the DataFrame
Parameters
by
(string | Array<string>) Key or array of keys to sort the DataFrame byoptions
Object? (optional, default{}
)
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, defaultfalse
)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 saveoptions
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 saveoptions
Object? (optional, default{}
)options.prettify
boolean Prettify JSON output (optional, defaulttrue
)
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
Returns DataFrame
isNA
Determines whether a value is N/A or not
Parameters
value
anyoptions
Object? Options (optional, default{}
)options.keep
Array<any> Array of falsy values not considered N/A (optional, default[0,false]
)
Returns boolean
Series
Parameters
Properties
length
number The number of values in the Seriesempty
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, default5
)
Returns Series
tail
Returns a new Series containing the last N values of the Series
Parameters
n
number Number of rows to select (optional, default5
)
Returns Series
slice
Returns a new Series with a slice of the original values
Parameters
start
number Zero-based index at which to start extractionend
number Zero-based index before which to end extraction (optional, defaultSeries.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 Seriesindex
number Index to insert the values at (optional, default0
)
Returns Series
dropNA
Drops N/A values from the Series
Parameters
options
Object? (optional, default{}
)
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, defaultfalse
)
Returns Series
filter
Filters values of the Series
Parameters
filter
callback Callback to applyoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
Returns Series
drop
Drops values from the Series
Parameters
filter
callback Callback to applyoptions
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
Returns Series
sort
Sorts the Series
Parameters
options
Object? (optional, default{}
)
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, defaultfalse
)
Returns Series
round
Round the values in the Series
Parameters
digits
number Number of digits for rounding (optional, default0
)options
Object? (optional, default{}
)options.inPlace
boolean Changes the current Series instead of returning a new one (optional, defaultfalse
)
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 saveoptions
Object? (optional, default{}
)options.name
string Column name to use (optional, default'series'
)
saveJSON
Saves the Series as a JSON file